shapely.simplify

Contents

shapely.simplify#

simplify(geometry, tolerance, preserve_topology=True, **kwargs)#

Return a simplified version of an input geometry.

The Douglas-Peucker algorithm is used to simplify the geometry.

Parameters:
geometryGeometry or array_like

Geometry or geometries to simplify.

tolerancefloat or array_like

The maximum allowed geometry displacement. The higher this value, the smaller the number of vertices in the resulting geometry.

preserve_topologybool, default True

By default (True), the operation will avoid creating invalid geometries (checking for collapses, ring-intersections, etc), but this is computationally more expensive.

**kwargs

See NumPy ufunc docs for other keyword arguments.

Notes

Deprecated since version 2.1.0: A deprecation warning is shown if preserve_topology is specified as a positional argument. This will need to be specified as a keyword argument in a future release.

Examples

>>> import shapely
>>> from shapely import LineString, Polygon
>>> line = LineString([(0, 0), (1, 10), (0, 20)])
>>> shapely.simplify(line, tolerance=0.9)
<LINESTRING (0 0, 1 10, 0 20)>
>>> shapely.simplify(line, tolerance=1)
<LINESTRING (0 0, 0 20)>
>>> polygon_with_hole = Polygon(
...     [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
...     holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.simplify(polygon_with_hole, tolerance=4, preserve_topology=True)
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (4 2, 2 4, 4 4, 4 2))>
>>> shapely.simplify(polygon_with_hole, tolerance=4, preserve_topology=False)
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>