ST_CoverageClean — Computes a clean (edge matched, non-overlapping, gap-cleared) polygonal coverage, given a non-clean input.
geometry ST_CoverageClean(geometry winset geom, float8 gapMaximumWidth = 0, float8 snappingDistance = -1, text overlapMergeStrategy = 'MERGE_LONGEST_BORDER');
A window function which adjusts the edges of a set of valid polygonal geometries to produce a clean coverage. Cleaning involves:
snapping vertices and edges to remove small discrepancies and ensure common edges are identically noded
merging overlaps into a parent polygon
merging narrow gaps into adjacent polygons
gapMaximumWidth controls which gaps between polygons are merged. Gaps with width <= this distance are merged into an adjacent polygon.
snappingDistance controls snapping of vertices and edges. The default (-1) automatically determines a snapping distance based on the input extent. Set to 0.0 to turn off snapping.
overlapMergeStrategy specifies how overlaps are merged into a parent polygon:
MERGE_LONGEST_BORDER - merges into polygon with longest common border
MERGE_MAX_AREA - merges into polygon with maximum area
MERGE_MIN_AREA - merges into polygon with minimum area
MERGE_MIN_INDEX - merges into polygon with smallest input index (defined by order of input polygons)
The result is a clean polygonal coverage that will pass validation by ST_CoverageInvalidEdges and can be input to coverage processing functions.
|
|
|
To aid in determining a maximum gap width, gaps can be computed by cleaning with |
Availability: 3.6.0 - requires GEOS >= 3.14.0
Clean a coverage containing overlaps and narrow gaps, and compare the cleaned polygons with the original invalid edges.
WITH coverage(id, geom) AS (VALUES
(1, 'POLYGON ((10 190,30 160,27 134.5,40 110,122 47,120 10,10 10,10 190))'::geometry),
(2, 'POLYGON ((150 190,10 190,30 160,50 140,40 110,50 80,130 70,135 111,140 130,140 160,150 190))'::geometry),
(3, 'POLYGON ((140 190,190 190,190 80,140 80,140 190))'::geometry),
(4, 'POLYGON ((190 10,120 10,97 77,160 90,170 70,190 80,190 10))'::geometry)
), processed AS (
SELECT id,
ST_CoverageClean(geom, 1) OVER () AS cleaned,
ST_CoverageInvalidEdges(geom) OVER () AS invalid_edges
FROM coverage
)
SELECT ST_Collect(cleaned ORDER BY id) AS cleaned,
ST_Collect(invalid_edges ORDER BY id) AS invalid_edges
FROM processed;
MULTIPOLYGON(((10 10,10 190,30 160,27 134.5,40 110,84.7 75.7,102 62.3,120 10,10 10)),((140 190,140 160,140 130,135 111,131.7 84.2,97 77,98 74,84.7 75.7,40 110,50 140,30 160,10 190,140 190)),((190 190,190 80,165 80,140 80,140 85.9,140 130,140 160,140 190,150 190,190 190)),((190 10,120 10,102 62.3,98 74,97 77,131.7 84.2,140 85.9,140 80,165 80,170 70,190 80,190 10))) | MULTILINESTRING((40 110,122 47,120 10),(40 110,50 80,130 70,135 111,140 130,140 160,150 190,10 190),(190 80,140 80,140 190,190 190),(120 10,97 77,160 90,170 70))