ST_SimplifyPreserveTopology — 使用道格拉斯-普克演算法,回傳一個簡化且有效的幾何表示。
geometry ST_SimplifyPreserveTopology(
geometry geom, float tolerance)
;
使用道格拉斯-普克演算法的變體,計算幾何圖形的簡化表示,該變體限制簡化以確保結果與輸入具有相同的拓撲結構。簡化的 tolerance
是距離值,單位為輸入 SRS 的單位。簡化會移除與簡化線條在容差距離內的頂點,只要拓撲結構得以保留。如果輸入有效且簡單,結果也會有效且簡單。
該函數可以使用任何類型的幾何圖形(包括 GeometryCollections)調用,但只會簡化線條和多邊形元素。對於多邊形輸入,結果將具有相同數量的環(外殼和孔洞),並且環不會交叉。環的端點可能會被簡化。對於線性的輸入,結果將具有相同數量的線條,並且如果原始幾何圖形中沒有相交,則線條也不會相交。線性幾何圖形的端點會被保留。
![]() |
|
此函數不會保留多邊形之間共用的邊界。如果需要,請使用 ST_CoverageSimplify。 |
由 GEOS 模組執行。
可用性:1.3.3
對於與 ST_Simplify 相同的範例,ST_SimplifyPreserveTopology 可防止過度簡化。圓最多可以變成一個正方形。
SELECT ST_Npoints(geom) AS np_before, ST_NPoints(ST_SimplifyPreserveTopology(geom, 0.1)) AS np01_notbadcircle, ST_NPoints(ST_SimplifyPreserveTopology(geom, 0.5)) AS np05_notquitecircle, ST_NPoints(ST_SimplifyPreserveTopology(geom, 1)) AS np1_octagon, ST_NPoints(ST_SimplifyPreserveTopology(geom, 10)) AS np10_square, ST_NPoints(ST_SimplifyPreserveTopology(geom, 100)) AS np100_stillsquare FROM (SELECT ST_Buffer('POINT(1 3)', 10,12) AS geom) AS t; np_before | np01_notbadcircle | np05_notquitecircle | np1_octagon | np10_square | np100_stillsquare -----------+-------------------+---------------------+-------------+-------------+------------------- 49 | 33 | 17 | 9 | 5 | 5
簡化一組線條,保留不相交線條的拓撲結構。
SELECT ST_SimplifyPreserveTopology( 'MULTILINESTRING ((20 180, 20 150, 50 150, 50 100, 110 150, 150 140, 170 120), (20 10, 80 30, 90 120), (90 120, 130 130), (130 130, 130 70, 160 40, 180 60, 180 90, 140 80), (50 40, 70 40, 80 70, 70 60, 60 60, 50 50, 50 40))', 40);
簡化 MultiPolygon,保留外殼和孔洞的拓撲結構。
SELECT ST_SimplifyPreserveTopology( 'MULTIPOLYGON (((90 110, 80 180, 50 160, 10 170, 10 140, 20 110, 90 110)), ((40 80, 100 100, 120 160, 170 180, 190 70, 140 10, 110 40, 60 40, 40 80), (180 70, 170 110, 142.5 128.5, 128.5 77.5, 90 60, 180 70)))', 40);