shapely.coverage_simplify

shapely.coverage_simplify#

coverage_simplify(geometry, tolerance, *, simplify_boundary=True)#

Return a simplified version of an input geometry using coverage simplification.

Note

‘coverage_simplify’ requires at least GEOS 3.12.0.

Assumes that the geometry forms a polygonal coverage. Under this assumption, the function simplifies the edges using the Visvalingam-Whyatt algorithm, while preserving a valid coverage. In the most simplified case, polygons are reduced to triangles.

A collection of valid polygons is considered a coverage if the polygons are:

  • Non-overlapping - polygons do not overlap (their interiors do not intersect)

  • Edge-Matched - vertices along shared edges are identical

The function allows simplification of all edges including the outer boundaries of the coverage or simplification of only the inner (shared) edges.

If there are other geometry types than Polygons or MultiPolygons present, the function will raise an error.

If the geometry is polygonal but does not form a valid coverage due to overlaps, it will be simplified but it may result in invalid topology.

Added in version 2.1.0.

Parameters:
geometryGeometry or array_like
tolerancefloat or array_like

The degree of simplification roughly equal to the square root of the area of triangles that will be removed.

simplify_boundarybool, optional

By default (True), simplifies both internal edges of the coverage as well as its boundary. If set to False, only simplifies internal edges.

Returns:
numpy.ndarray | shapely.Geometry

Examples

>>> import shapely
>>> from shapely import Polygon
>>> poly = Polygon([(0, 0), (20, 0), (20, 10), (10, 5), (0, 10), (0, 0)])
>>> shapely.coverage_simplify(poly, tolerance=2)
<POLYGON ((0 0, 20 0, 20 10, 10 5, 0 10, 0 0))>