- Mastering PostGIS
- Dominik Mikiewicz Michal Mackiewicz Tomasz Nycz
- 233字
- 2021-07-02 22:52:26
LineString decomposition
This process is also similar to MultiPoint decomposition. The points can be extracted one at a time or dumped into a geometry dump. Aside from these generic methods, there are also special functions for finding the start or end point of a line.
- First, let's find the count of the vertices in a LineString. A generic ST_NPoints function can be used for that:
SELECT
ST_NPoints(ST_MakeLine(ST_MakePoint(20,50),
ST_MakePoint(19.95,49.98)));
2
The ST_NPoints works for any geometry type--not just for LineStrings, but also LinearRings, polygons, their multi-variants, and even for points, in which case it will return 1. There is also a ST_NumPoints function, which works for LineStrings only.
The individual points are extracted from a LineString by the ST_PointN function, which is not unlike ST_GeometryN used for Multi-geometry decomposition.
SELECT
ST_AsText(ST_PointN(ST_MakeLine(ARRAY[
ST_MakePoint(20,50),ST_MakePoint(19.95,49.98),
ST_MakePoint(19.90,49.96)]),2));
POINT(19.95 49.98)
- Dumping the points into a set of rows is also similar to dumping a Multi-geometry. The only difference is that the function used is named ST_DumpPoints. The geometry dump compound type is a direct output from this function:
SELECT
ST_DumpPoints(ST_MakeLine(ARRAY[
ST_MakePoint(20,50),ST_MakePoint(19.95,49.98),
ST_MakePoint(19.90,49.96)]));
st_dumppoints
--------------------------------------------------
({1},010100000000000000000034400000000000004940)
({2},01010000003333333333F333403D0AD7A370FD4840)
({3},01010000006666666666E633407B14AE47E1FA4840)
- And for accessing the vertices' geometry, we can do the following:
SELECT
(ST_DumpPoints(ST_MakeLine(ARRAY[
ST_MakePoint(20,50),ST_MakePoint(19.95,49.98),
ST_MakePoint(19.90,49.96)]))).geom;
geom
--------------------------------------------
010100000000000000000034400000000000004940
01010000003333333333F333403D0AD7A370FD4840
01010000006666666666E633407B14AE47E1FA4840
- Finally, there are specialized methods for finding the first and last vertices of LineStrings. They are named ST_StartPoint and ST_EndPoint:
SELECT
ST_AsText(ST_StartPoint(ST_MakeLine(ARRAY[
ST_MakePoint(20,50),ST_MakePoint(19.95,49.98),
ST_MakePoint(19.90,49.96)])));
POINT(20 50)
SELECT
ST_AsText(ST_EndPoint(ST_MakeLine(ARRAY[
ST_MakePoint(20,50),ST_MakePoint(19.95,49.98),
ST_MakePoint(19.90,49.96)])));
POINT(19.9 49.96)
推薦閱讀
- 大數(shù)據(jù)管理系統(tǒng)
- Hands-On Internet of Things with MQTT
- 大數(shù)據(jù)戰(zhàn)爭:人工智能時代不能不說的事
- Mastering VMware vSphere 6.5
- Mastering Salesforce CRM Administration
- 系統(tǒng)安裝與重裝
- 完全掌握AutoCAD 2008中文版:機(jī)械篇
- 電腦主板現(xiàn)場維修實(shí)錄
- Machine Learning with the Elastic Stack
- 大數(shù)據(jù)案例精析
- 和機(jī)器人一起進(jìn)化
- PowerMill 2020五軸數(shù)控加工編程應(yīng)用實(shí)例
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)實(shí)訓(xùn)·職業(yè)模塊
- 中國戰(zhàn)略性新興產(chǎn)業(yè)研究與發(fā)展·數(shù)控系統(tǒng)
- Eclipse全程指南