Name

ST_CoverageClean — Computes a clean (edge matched, non-overlapping, gap-cleared) polygonal coverage, given a non-clean input.

Synopsis

geometry ST_CoverageClean(geometry winset geom, float8 snappingDistance = -1, float8 gapMaximumWidth = 0, text overlapMergeStrategy = 'MERGE_LONGEST_BORDER');

説明

A window function which alters the edges of a polygonal coverage to ensure that none of the polygons overlap, that small gaps are snapped away, and that all shared edges are exactly identical. The result is a clean coverage that will pass validation tests like ST_CoverageInvalidEdges

The gapMaximumWidth controls the cleaning of gaps between polygons. Gaps smaller than this tolerance will be closed.

The snappingDistance controls the node snapping step, when nearby vertices are snapped together. The default setting (-1) applies an automatic snapping distance based on an analysis of the input. Set to 0.0 to turn off all snapping.

The overlapMergeStrategy controls the algorithm used to determine which neighboring polygons to merge overlapping areas into.

MERGE_LONGEST_BORDER chooses polygon with longest common border

MERGE_MAX_AREA chooses polygon with maximum area

MERGE_MIN_AREA chooses polygon with minimum area

MERGE_MIN_INDEX chooses polygon with smallest input index

Availability: 3.6.0 - requires GEOS >= 3.14.0

-- Populate demo table
CREATE TABLE example AS SELECT * FROM (VALUES
  (1, 'POLYGON ((10 190, 30 160, 40 110, 100 70, 120 10, 10 10, 10 190))'::geometry),
  (2, 'POLYGON ((100 190, 10 190, 30 160, 40 110, 50 80, 74 110.5, 100 130, 140 120, 140 160, 100 190))'::geometry),
  (3, 'POLYGON ((140 190, 190 190, 190 80, 140 80, 140 190))'::geometry),
  (4, 'POLYGON ((180 40, 120 10, 100 70, 140 80, 190 80, 180 40))'::geometry)
) AS v(id, geom);

-- Prove it is a dirty coverage
SELECT ST_AsText(ST_CoverageInvalidEdges(geom) OVER ())
  FROM example;

-- Clean the coverage
CREATE TABLE example_clean AS
  SELECT id, ST_CoverageClean(geom) OVER () AS GEOM
  FROM example;

-- Prove it is a clean coverage
SELECT ST_AsText(ST_CoverageInvalidEdges(geom) OVER ())
  FROM example_clean;