PostGISCoverages

ST_CoverageInvalidEdges

What is ST_CoverageInvalidEdges?

ST_CoverageInvalidEdges is a PostGIS window function that inspects a set of polygons intended to form a coverage (adjacent, non-overlapping) and returns the edges that break the coverage rules. A valid coverage has no gaps and no overlaps between its features.

SQL
ST_CoverageInvalidEdges(geometry winset geom, float tolerance = 0) WINDOW → geometry

For each input polygon it returns a MultiLineString of edges that are mismatched with neighbours, or NULL if the polygon is consistent.

When would you use ST_CoverageInvalidEdges?

Use ST_CoverageInvalidEdges to QA cadastral, administrative, or land-cover datasets — anywhere polygons should tile a region without gaps or overlaps. It highlights exactly which edges are problematic so you can fix them, rather than just flagging features as invalid.

SQL
1SELECT id, ST_CoverageInvalidEdges(geom) OVER () AS bad_edges
2FROM parcels
3WHERE ST_CoverageInvalidEdges(geom) OVER () IS NOT NULL;

FAQs

What exactly is a "coverage"?

A coverage is a set of polygons whose interiors do not overlap and whose boundaries line up exactly where they meet. Think of administrative boundaries or a land-cover classification — every point in the study area is in exactly one polygon, with no gaps and no overlaps.

What does the tolerance parameter do?

tolerance lets the check accept very small gaps or offsets as still being aligned. This is important for real-world data where coordinates can differ by sub-millimetre amounts due to rounding. Start with 0 and only raise it if you see false positives for effectively-aligned edges.

Why is this a window function?

Coverage validity is a property of a set of polygons, not of a single feature. Window semantics let the function see all rows in the partition at once to check edge alignment. Without a partition the entire table is treated as one coverage.

How do I fix the bad edges it finds?

Use ST_Snap, ST_CoverageSimplify, or topology editing to align mismatched edges. Visualising the result in QGIS is the fastest way to spot the error patterns (dangles, sliver gaps, overlaps) and pick a fix strategy.