Skip to content

Coverage (polygonal)

Validate, clean, simplify, and union edge-sharing polygon coverages.

Related: Validation & repair

coverage_clean

Accepted call forms
coverage_clean(
    values: Polygon
    | MultiPolygon
    | GeometryArray[Polygon | MultiPolygon]
    | Iterable[
        Polygon
        | MultiPolygon
        | Buffer
        | Mapping[str, Any]
        | SupportsGeoInterface
    ],
    *,
    grid_size: float = 0.0,
    gap_width: float = 0.0,
    overlap_rule: Literal[
        'longest_border', 'max_area', 'min_area', 'min_index'
    ] = 'longest_border',
    metric: Literal['cartesian'] | Sphere | None = None,
    unit: Literal['meters'] | None = None,
) -> GeometryArray[Polygon | MultiPolygon]
coverage_clean(
    values: GeometryArray[Polygon | MultiPolygon | None]
    | Iterable[
        Polygon
        | MultiPolygon
        | Buffer
        | Mapping[str, Any]
        | SupportsGeoInterface
        | None
    ],
    *,
    grid_size: float = 0.0,
    gap_width: float = 0.0,
    overlap_rule: Literal[
        'longest_border', 'max_area', 'min_area', 'min_index'
    ] = 'longest_border',
    metric: Literal['cartesian'] | Sphere | None = None,
    unit: Literal['meters'] | None = None,
) -> GeometryArray[Polygon | MultiPolygon | None]

Clean a near-coverage into a polygonal coverage.

Optionally snaps vertices, nodes every boundary, then assigns each face of the arrangement to one row. Overlaps are assigned first. Each complete connected uncovered region whose boundary-clearance width is at most gap_width then merges into its remaining neighbor with the longest shared border. A narrow crack opening into a wider chamber is left whole. All score ties choose the lowest original row. Shared interfaces use the same noded geometry; original row order, missingness, and Space survive.

Geographic gaps have no exempt exterior or largest component. A nearly Full coverage's only narrow gap can be filled. The unbounded planar exterior is never filled; all-empty inputs have no recipient and remain empty.

Parameters:

Name Type Description Default
values Geometry, GeometryArray, or iterable of Geometry

One coverage row or multiple rows (Polygon or MultiPolygon each).

required
grid_size float

Finite non-negative vertex snapping grid in coordinate space: geographic CRSs use native angular units, projected CRSs use native linear units, and CRS-free inputs use raw coordinate units. 0 preserves input coordinates and disables snapping. Unlike snap_to_grid(grid_size=...), this operation accepts zero.

0.0
gap_width float

Finite non-negative whole-gap diameter threshold; zero disables filling. Diameter is twice the maximum distance to the gap's own model boundary. Units follow metric and unit. An unresolved numerical comparison leaves the complete component unfilled.

0.0
overlap_rule str

Which row keeps a region covered more than once: 'longest_border', 'max_area', 'min_area', or 'min_index'. Area and border ranks use the selected measurement model over original row regions and complete retained curves. This choice does not select the recipient of a filled gap.

'longest_border'
metric 'cartesian'

The default uses physical meters and square meters for geographic CRSs, including planar values, native linear units for projected CRSs, and raw units without a CRS. 'cartesian' requires a planar Space. Sphere changes measurement without changing geometry, CRS, or the original source law used to carry ordinates. Planar longitude/latitude gaps measure their own boundary images, not a unique physical footprint.

'cartesian'
unit 'meters'

Request meters instead of projected native units. Requires a compatible CRS; angular Cartesian coordinates cannot be converted to meters.

'meters'

Returns:

Type Description
GeometryArray

One cleaned Polygon/MultiPolygon per input row.

Raises:

Type Description
GeometryTypeError

If a row is not a Polygon or MultiPolygon.

GeometryError

If grid_size or gap_width is negative or non-finite.

InvalidGeometryError

If an input row is individually invalid, or an explicitly requested snap-repair cannot produce a valid grid-aligned result. Repair invalid individual rows before cleaning the coverage.

CRSMismatchError

If the rows' CRS or coordinate-epoch metadata differ.

Notes

Z is averaged over eligible original records belonging to the recipient row. M is dropped on material measure conflict. An unavailable axis is dropped only for that row; another row's records neither supply nor erase its values.

See Also

coverage_is_valid : Test whether a polygonal coverage is already valid.

Examples:

>>> import gometry as gm
>>> rows = [gm.box(0, 0, 1.2, 1), gm.box(1, 0, 2, 1)]
>>> gm.coverage_is_valid(rows)
False
>>> cleaned = gm.coverage_clean(rows)
>>> gm.coverage_is_valid(cleaned)
True

coverage_invalid_edges

Accepted call forms
coverage_invalid_edges(
    values: Polygon
    | MultiPolygon
    | GeometryArray[Polygon | MultiPolygon]
    | Iterable[
        Polygon
        | MultiPolygon
        | Buffer
        | Mapping[str, Any]
        | SupportsGeoInterface
    ],
    *,
    gap_width: float = 0.0,
    metric: Literal['cartesian'] | Sphere | None = None,
    unit: Literal['meters'] | None = None,
) -> GeometryArray[LineString | MultiLineString]
coverage_invalid_edges(
    values: GeometryArray[Polygon | MultiPolygon | None]
    | Iterable[
        Polygon
        | MultiPolygon
        | Buffer
        | Mapping[str, Any]
        | SupportsGeoInterface
        | None
    ],
    *,
    gap_width: float = 0.0,
    metric: Literal['cartesian'] | Sphere | None = None,
    unit: Literal['meters'] | None = None,
) -> GeometryArray[LineString | MultiLineString | None]

Per-row invalid coverage boundary linework.

Each output row merges the row's boundary segments that violate the coverage contract (overlaps, T-joins, slivers, and — with gap_width — narrow gaps); rows that are clean come back as LINESTRING EMPTY.

Parameters:

Name Type Description Default
values Geometry, GeometryArray, or iterable of Geometry

One coverage row or multiple rows (Polygon or MultiPolygon each).

required
gap_width float

Finite non-negative unmatched-boundary proximity threshold; zero disables proximity checks. Units follow metric and unit.

0.0
metric 'cartesian'

Measurement model for proximity checks. The default uses physical meters for geographic CRSs, native linear units for projected CRSs, and raw units without a CRS. 'cartesian' requires a planar Space. Sphere changes measurement without changing geometry or its CRS.

'cartesian'
unit 'meters'

Request meters instead of projected native units. Requires a compatible CRS; angular Cartesian coordinates cannot be converted to meters.

'meters'

Returns:

Type Description
GeometryArray

One LineString/MultiLineString per present input row, retaining row order, missing slots, Space, and available row-scoped Z/M ordinates. Full/Full overlap has no fabricated diagnostic boundary.

Raises:

Type Description
GeometryTypeError

If a row is not a Polygon or MultiPolygon.

GeometryError

If gap_width is negative or non-finite.

CRSMismatchError

If the rows' CRS or coordinate-epoch metadata differ.

See Also

coverage_is_valid : The boolean verdict.

Examples:

>>> import gometry as gm
>>> len(gm.coverage_invalid_edges(
...     [gm.box(0, 0, 1, 1), gm.box(0.5, 0, 1.5, 1)]))
2

coverage_is_valid

coverage_is_valid(
    values: Polygon
    | MultiPolygon
    | GeometryArray[Polygon | MultiPolygon]
    | Iterable[
        Polygon
        | MultiPolygon
        | Buffer
        | Mapping[str, Any]
        | SupportsGeoInterface
        | None
    ],
    *,
    gap_width: float = 0.0,
    metric: Literal['cartesian'] | Sphere | None = None,
    unit: Literal['meters'] | None = None,
) -> bool

Test whether geometries form a valid polygonal coverage.

A polygonal coverage (parcels, admin boundaries) is a set of polygons with no interior overlaps whose shared boundaries use vector-identical linework. Distinct from the DGGS cell Coverage classes.

Parameters:

Name Type Description Default
values Geometry, GeometryArray, or iterable of Geometry

One coverage row or multiple rows (Polygon or MultiPolygon each).

required
gap_width float

Finite non-negative unmatched-boundary proximity threshold; zero disables proximity checks. Units follow metric and unit.

0.0
metric 'cartesian'

Measurement model for proximity checks. The default uses physical measurement in meters for a geographic CRS, including planar values, native linear units for a projected CRS, and raw units without a CRS. 'cartesian' requires a planar Space. Sphere selects spherical measurement without changing geometry or its CRS.

'cartesian'
unit 'meters'

Request meters instead of projected native units. Requires a compatible CRS; angular Cartesian coordinates cannot be converted to meters.

'meters'

Returns:

Type Description
bool

True when all present rows are individually valid and have no overlap, mismatched interface, or requested proximity violation. Empty and all-missing inputs are valid. A Full/Full overlap is invalid even though no boundary linework exists to report. An unresolved requested proximity comparison returns False.

Raises:

Type Description
GeometryTypeError

If a row is not a Polygon or MultiPolygon.

GeometryError

If gap_width is negative or non-finite.

CRSMismatchError

If the rows' CRS or coordinate-epoch metadata differ.

See Also

coverage_invalid_edges : The offending linework itself. coverage_clean : Rebuild an exact coverage from a near-coverage.

Examples:

>>> import gometry as gm
>>> grid = gm.GeometryArray([
...     gm.Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]),
...     gm.Polygon([(1, 0), (2, 0), (2, 1), (1, 1)]),
... ])
>>> gm.coverage_is_valid(grid)
True
>>> gm.coverage_is_valid(gm.GeometryArray([
...     gm.Polygon([(0, 0), (1.1, 0), (1.1, 1), (0, 1)]),
...     gm.Polygon([(1, 0), (2, 0), (2, 1), (1, 1)]),
... ]))
False

coverage_simplify

Accepted call forms
coverage_simplify(
    values: Polygon
    | MultiPolygon
    | GeometryArray[Polygon | MultiPolygon]
    | Iterable[
        Polygon
        | MultiPolygon
        | Buffer
        | Mapping[str, Any]
        | SupportsGeoInterface
    ],
    tolerance: float,
    *,
    method: Literal['vw', 'dp'] = 'vw',
    simplify_boundary: bool = True,
    metric: Literal['cartesian'] | Sphere | None = None,
    unit: Literal['meters'] | None = None,
) -> GeometryArray[Polygon | MultiPolygon]
coverage_simplify(
    values: GeometryArray[Polygon | MultiPolygon | None]
    | Iterable[
        Polygon
        | MultiPolygon
        | Buffer
        | Mapping[str, Any]
        | SupportsGeoInterface
        | None
    ],
    tolerance: float,
    *,
    method: Literal['vw', 'dp'] = 'vw',
    simplify_boundary: bool = True,
    metric: Literal['cartesian'] | Sphere | None = None,
    unit: Literal['meters'] | None = None,
) -> GeometryArray[Polygon | MultiPolygon | None]

Simplify a VALID polygonal coverage's boundaries, preserving its topology.

Shared boundaries are simplified once and reused by both neighbors. A model-native topology guard preserves contacts, containment and selected polygon interiors across all rows. Conservative retention can keep extra vertices. Input must be a valid coverage; invalid rows raise. For a near-coverage that needs overlap or gap repair, use coverage_clean first. Retained sites resolve qualified Z/M from their original recipient row; metric selection changes neither stored Space nor CRS.

Parameters:

Name Type Description Default
values Geometry, GeometryArray, or iterable of Geometry

One coverage row or multiple rows (Polygon or MultiPolygon each).

required
tolerance float

Finite non-negative distance scale in the selected metric's units. Defaults are meters for geographic CRSs, native linear units for projected CRSs, and raw coordinate units without a CRS.

required
method ('vw', 'dp')

Importance criterion: 'vw' is area-based (Visvalingam-Whyatt), 'dp' is distance-based (Douglas-Peucker). Both run under the same topology guard. DP checks each complete original source window, including detail removed earlier. VW compares the selected-surface deviation area with tolerance**2 / 2; it does not promise a maximum displacement. Planar geographic curves retain literal sheet multiplicity; Chart and Spherical curves retain their native branches.

'vw'
simplify_boundary bool

Also simplify exterior (unshared) boundaries; False pins them and simplifies only the shared interfaces.

True
metric 'cartesian'

Select measurement without reinterpreting geometry. Geographic CRSs use their ellipsoid by default; Sphere selects a measuring sphere. 'cartesian' is available only in planar Space.

'cartesian'
unit 'meters'

Use the resolved metric's tolerance scale by default. 'meters' requires a CRS and converts projected linear units to meters.

'meters'

Returns:

Type Description
GeometryArray

One simplified Polygon/MultiPolygon per input row.

Raises:

Type Description
GeometryTypeError

If a row is not a Polygon or MultiPolygon.

GeometryError

If tolerance is negative or non-finite.

CRSMismatchError

If the rows' CRS or coordinate-epoch metadata differ.

CRSError

If the metric cannot be resolved for the rows' Space and CRS.

InvalidGeometryError

If the rows are not a valid polygonal coverage.

See Also

Geometry.simplify : Per-geometry simplify (not coverage-topology-preserving). coverage_is_valid : Whether the rows form a valid polygonal coverage. coverage_clean : Rebuild a near-coverage before simplification.

Examples:

>>> import gometry as gm
>>> left = gm.Polygon([(0, 0), (1, 0), (1.05, 0.5), (1, 1), (0, 1)])
>>> right = gm.Polygon([(1, 0), (2, 0), (2, 1), (1, 1), (1.05, 0.5)])
>>> out = gm.coverage_simplify([left, right], 0.5)
>>> out.to_wkt()[0]
'POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))'

coverage_union_all

coverage_union_all(
    values: Polygon
    | MultiPolygon
    | GeometryArray[Polygon | MultiPolygon | None]
    | Iterable[
        Polygon
        | MultiPolygon
        | Buffer
        | Mapping[str, Any]
        | SupportsGeoInterface
        | None
    ],
) -> Polygon | MultiPolygon

Union a polygonal coverage into one geometry by dissolving shared edges.

A fast specialization of union_all for a valid coverage — polygons that tile a region edge-to-edge with no overlaps and no T-junctions (see coverage_is_valid). It cancels the interior edges shared between adjacent polygons rather than general noding and classification. On overlapping or badly-noded input it raises before the specialized dissolve runs; use union_all there.

In a geographic CRS, rows whose raw bounds are unsound at the periodic seam, a pole, or a non-canonical longitude are dissolved in the exact geographic topology and drawn as admitted chart-safe pieces. Canonical seam-free and pole-free rows retain the direct path. The result preserves the shared CRS and coordinate epoch; polygon order and cyclic ring starts are unspecified. Spherical rows use their great-circle boundaries and selected interiors. Empty or all-missing input produces an empty Polygon with the input Space.

Parameters:

Name Type Description Default
values Geometry, GeometryArray, or iterable of Geometry

One polygonal row or multiple rows of a valid coverage. Missing array rows are skipped.

required

Returns:

Type Description
Geometry

A single Polygon/MultiPolygon covering the merged area.

Raises:

Type Description
CRSMismatchError

If the operands' CRS or coordinate-epoch metadata differ.

InvalidGeometryError

If the rows are not a valid coverage, or coordinates are outside their geographic CRS domain.

See Also

union_all : General multi-geometry union (handles overlaps). coverage_is_valid : Whether the rows form a valid polygonal coverage.

Examples:

>>> import gometry as gm
>>> tiles = gm.GeometryArray([gm.box(0, 0, 1, 1), gm.box(1, 0, 2, 1)])
>>> merged = gm.coverage_union_all(tiles)
>>> (merged.geometry_type, round(merged.area, 6))
('Polygon', 2.0)