ST_Simplify — 使用 Douglas-Peucker 演算法,傳回幾何圖形的簡化表示。
geometry ST_Simplify(
geometry geom, float tolerance)
;
geometry ST_Simplify(
geometry geom, float tolerance, boolean preserveCollapsed)
;
使用 Douglas-Peucker 演算法 計算幾何圖形的簡化表示。簡化 tolerance
是距離值,單位與輸入 SRS 相同。簡化會移除位於簡化線條容差距離內的頂點。即使輸入有效,結果也可能無效。
此函式可以使用任何類型的幾何圖形(包括 GeometryCollections)來呼叫,但僅簡化線和多邊形元素。保留線性幾何的端點。
preserveCollapsed
標誌會保留在給定容差下會被移除的小型幾何圖形。例如,如果使用 10 公尺的容差簡化 1 公尺長的線,當 preserveCollapsed
為 true 時,該線不會消失。此標誌對於渲染目的很有用,可以防止非常小的特徵從地圖上消失。
![]() |
|
傳回的幾何圖形可能會失去其簡單性(請參閱 ST_IsSimple),拓樸可能不會保留,多邊形結果可能無效(請參閱 ST_IsValid)。使用 ST_SimplifyPreserveTopology 來保留拓樸並確保有效性。 |
![]() |
|
此函式不會保留多邊形之間共用的邊界。如果需要此功能,請使用 ST_CoverageSimplify。 |
可用性:1.2.2
一個簡化過多的圓會變成三角形,中度簡化會變成八邊形,
SELECT ST_Npoints(geom) AS np_before, ST_NPoints(ST_Simplify(geom, 0.1)) AS np01_notbadcircle, ST_NPoints(ST_Simplify(geom, 0.5)) AS np05_notquitecircle, ST_NPoints(ST_Simplify(geom, 1)) AS np1_octagon, ST_NPoints(ST_Simplify(geom, 10)) AS np10_triangle, (ST_Simplify(geom, 100) is null) AS np100_geometrygoesaway FROM (SELECT ST_Buffer('POINT(1 3)', 10,12) As geom) AS t; np_before | np01_notbadcircle | np05_notquitecircle | np1_octagon | np10_triangle | np100_geometrygoesaway -----------+-------------------+---------------------+-------------+---------------+------------------------ 49 | 33 | 17 | 9 | 4 | t
簡化一組線。簡化後,線可能會相交。
SELECT ST_Simplify( '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_Simplify( '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);