- Mastering PostGIS
- Dominik Mikiewicz Michal Mackiewicz Tomasz Nycz
- 182字
- 2021-07-02 22:52:26
Polygon decomposition
There are two levels of polygon geometry decomposition: they can be broken down either into LineStrings or into points. Decomposition into points is very similar to decomposition of a LineString: the ST_DumpPoints is used:
SELECT ST_DumpPoints(
ST_MakePolygon(
ST_MakeLine(ARRAY[ST_MakePoint(20,50),ST_MakePoint(19.95,49.98), ST_MakePoint(19.90,49.90),ST_MakePoint(20,50)]),
ARRAY[ST_MakeLine(ARRAY[ST_MakePoint(19.95,49.97),ST_MakePoint(19.943,49.963), ST_MakePoint(19.955,49.965),ST_MakePoint(19.95,49.97)])]
)
);
st_dumppoints
------------------------------------------------------
("{1,1}",010100000000000000000034400000000000004940)
("{1,2}",01010000003333333333F333403D0AD7A370FD4840)
("{1,3}",01010000006666666666E633403333333333F34840)
("{1,4}",010100000000000000000034400000000000004940)
("{2,1}",01010000003333333333F333405C8FC2F528FC4840)
("{2,2}",0101000000C520B07268F133402506819543FB4840)
("{2,3}",010100000014AE47E17AF43340EC51B81E85FB4840)
("{2,4}",01010000003333333333F333405C8FC2F528FC4840)
There's a slight difference in the geometry dump format: the path array now consists of two numbers. The first one is the index of the ring (1 being the exterior ring, and the following numbers the subsequent interior rings), and the second is the index a of point in the ring.
For extracting whole rings, PostGIS offers the following possibilities:
- Dumping the rings into a set of rows. For that, ST_DumpRings is used:
SELECT ST_DumpRings(
ST_MakePolygon(
ST_MakeLine(ARRAY[ST_MakePoint(20,50),ST_MakePoint(19.95,49.98),
ST_MakePoint(19.90,49.90),ST_MakePoint(20,50)]),
ARRAY[ST_MakeLine(ARRAY[ST_MakePoint(19.95,49.97),ST_MakePoint
(19.943,49.963),
ST_MakePoint(19.955,49.965),ST_MakePoint(19.95,49.97)])]
)
);
st_dumprings
----------------------------------
({1},01030000000100000004000000(...)
- Extracting the exterior ring:
SELECT ST_ExteriorRing(
ST_MakePolygon(
ST_MakeLine(ARRAY[ST_MakePoint(20,50),ST_MakePoint(19.95,49.98),
ST_MakePoint(19.90,49.90),ST_MakePoint(20,50)]),
ARRAY[ST_MakeLine(ARRAY[ST_MakePoint(19.95,49.97),
ST_MakePoint(19.943,49.963),ST_MakePoint(19.955,49.965),
ST_MakePoint(19.95,49.97)])]
)
);
st_exteriorring
--------------------------
01020000000400000000(...)
- Extracting the interior rings based on their index:
SELECT ST_InteriorRingN(
ST_MakePolygon(
ST_MakeLine(ARRAY[ST_MakePoint(20,50),ST_MakePoint(19.95,49.98),
ST_MakePoint(19.90,49.90),ST_MakePoint(20,50)]),
ARRAY[ST_MakeLine(ARRAY[ST_MakePoint(19.95,49.97),
ST_MakePoint(19.943,49.963),
ST_MakePoint(19.955,49.965),ST_MakePoint(19.95,49.97)])]
), 1
);
st_interiorringn
---------------------------
010200000004000000333(...)

Interior ring extracted from a polygon.
推薦閱讀
- 構(gòu)建高質(zhì)量的C#代碼
- 網(wǎng)絡(luò)服務(wù)器架設(shè)(Windows Server+Linux Server)
- ServiceNow Cookbook
- 機(jī)器學(xué)習(xí)與大數(shù)據(jù)技術(shù)
- 精通Excel VBA
- 大數(shù)據(jù)平臺(tái)異常檢測(cè)分析系統(tǒng)的若干關(guān)鍵技術(shù)研究
- 傳感器與物聯(lián)網(wǎng)技術(shù)
- 空間站多臂機(jī)器人運(yùn)動(dòng)控制研究
- 面向?qū)ο蟪绦蛟O(shè)計(jì)綜合實(shí)踐
- 軟件工程及實(shí)踐
- Building a BeagleBone Black Super Cluster
- 強(qiáng)化學(xué)習(xí)
- Mastering Ansible(Second Edition)
- 基于RPA技術(shù)財(cái)務(wù)機(jī)器人的應(yīng)用與研究
- 計(jì)算機(jī)硬件技術(shù)基礎(chǔ)(第2版)