shapely.voronoi_polygons

shapely.voronoi_polygons#

voronoi_polygons(geometry, tolerance=0.0, extend_to=None, only_edges=False, ordered=False, **kwargs)#

Compute a Voronoi diagram from the vertices of an input geometry.

The output is a geometrycollection containing polygons (default) or linestrings (see only_edges). Returns empty if an input geometry contains less than 2 vertices or if the provided extent has zero area.

Parameters:
geometryGeometry or array_like

Geometry or geometries for which to compute the Voronoi diagram.

tolerancefloat or array_like, default 0.0

Snap input vertices together if their distance is less than this value.

extend_toGeometry or array_like, optional

If provided, the diagram will be extended to cover the envelope of this geometry (unless this envelope is smaller than the input geometry).

only_edgesbool or array_like, default False

If set to True, the triangulation will return a collection of linestrings instead of polygons.

orderedbool or array_like, default False

If set to True, polygons within the GeometryCollection will be ordered according to the order of the input vertices. Note that this may slow down the computation. Requires GEOS >= 3.12.0.

Added in version 2.1.0.

**kwargs

See NumPy ufunc docs for other keyword arguments.

Notes

Deprecated since version 2.1.0: A deprecation warning is shown if extend_to, only_edges or ordered are specified as positional arguments. In a future release, these will need to be specified as keyword arguments.

Examples

>>> import shapely
>>> from shapely import LineString, MultiPoint, Point
>>> points = MultiPoint([(2, 2), (4, 2)])
>>> shapely.voronoi_polygons(points).normalize()
<GEOMETRYCOLLECTION (POLYGON ((3 0, 3 4, 6 4, 6 0, 3 0)), POLYGON ((0 0, 0 4...>
>>> shapely.voronoi_polygons(points, only_edges=True)
<MULTILINESTRING ((3 4, 3 0))>
>>> shapely.voronoi_polygons(MultiPoint([(2, 2), (4, 2), (4.2, 2)]), 0.5, only_edges=True)
<MULTILINESTRING ((3 4.2, 3 -0.2))>
>>> shapely.voronoi_polygons(points, extend_to=LineString([(0, 0), (10, 10)]), only_edges=True)
<MULTILINESTRING ((3 10, 3 0))>
>>> shapely.voronoi_polygons(LineString([(2, 2), (4, 2)]), only_edges=True)
<MULTILINESTRING ((3 4, 3 0))>
>>> shapely.voronoi_polygons(Point(2, 2))
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.voronoi_polygons(points, ordered=True)
<GEOMETRYCOLLECTION (POLYGON ((0 0, 0 4, 3 4, 3 0, 0 0)), POLYGON ((6 4, 6 0...>