MCPcopy Create free account
hub / github.com/shapely/shapely / voronoi_polygons

Function voronoi_polygons

shapely/constructive.py:1282–1348  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

1280)
1281@multithreading_enabled
1282def voronoi_polygons(
1283 geometry, tolerance=0.0, extend_to=None, only_edges=False, ordered=False, **kwargs
1284):
1285 """Compute a Voronoi diagram from the vertices of an input geometry.
1286
1287 The output is a geometrycollection containing polygons (default)
1288 or linestrings (see only_edges). Returns empty if an input geometry
1289 contains less than 2 vertices or if the provided extent has zero area.
1290
1291 Parameters
1292 ----------
1293 geometry : Geometry or array_like
1294 Geometry or geometries for which to compute the Voronoi diagram.
1295 tolerance : float or array_like, default 0.0
1296 Snap input vertices together if their distance is less than this value.
1297 extend_to : Geometry or array_like, optional
1298 If provided, the diagram will be extended to cover the envelope of this
1299 geometry (unless this envelope is smaller than the input geometry).
1300 only_edges : bool or array_like, default False
1301 If set to True, the triangulation will return a collection of
1302 linestrings instead of polygons.
1303 ordered : bool or array_like, default False
1304 If set to True, polygons within the GeometryCollection will be ordered
1305 according to the order of the input vertices. Note that this may slow
1306 down the computation. Requires GEOS >= 3.12.0.
1307
1308 .. versionadded:: 2.1.0
1309 **kwargs
1310 See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
1311
1312 Notes
1313 -----
1314
1315 .. deprecated:: 2.1.0
1316 A deprecation warning is shown if ``extend_to``, ``only_edges`` or
1317 ``ordered`` are specified as positional arguments. In a future
1318 release, these will need to be specified as keyword arguments.
1319
1320 Examples
1321 --------
1322 >>> import shapely
1323 >>> from shapely import LineString, MultiPoint, Point
1324 >>> points = MultiPoint([(2, 2), (4, 2)])
1325 >>> shapely.voronoi_polygons(points).normalize()
1326 <GEOMETRYCOLLECTION (POLYGON ((3 0, 3 4, 6 4, 6 0, 3 0)), POLYGON ((0 0, 0 4...>
1327 >>> shapely.voronoi_polygons(points, only_edges=True)
1328 <MULTILINESTRING ((3 4, 3 0))>
1329 >>> shapely.voronoi_polygons(MultiPoint([(2, 2), (4, 2), (4.2, 2)]), 0.5, only_edges=True)
1330 <MULTILINESTRING ((3 4.2, 3 -0.2))>
1331 >>> shapely.voronoi_polygons(points, extend_to=LineString([(0, 0), (10, 10)]), only_edges=True)
1332 <MULTILINESTRING ((3 10, 3 0))>
1333 >>> shapely.voronoi_polygons(LineString([(2, 2), (4, 2)]), only_edges=True)
1334 <MULTILINESTRING ((3 4, 3 0))>
1335 >>> shapely.voronoi_polygons(Point(2, 2))
1336 <GEOMETRYCOLLECTION EMPTY>
1337 >>> shapely.voronoi_polygons(points, ordered=True)
1338 <GEOMETRYCOLLECTION (POLYGON ((0 0, 0 4, 3 4, 3 0, 0 0)), POLYGON ((6 4, 6 0...>
1339

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…