shapely.delaunay_triangles

shapely.delaunay_triangles#

delaunay_triangles(geometry, tolerance=0.0, only_edges=False, **kwargs)#

Compute a Delaunay triangulation around the vertices of an input geometry.

The output is a geometrycollection containing polygons (default) or linestrings (see only_edges). Returns an empty geometry for input geometries that contain less than 3 vertices.

Parameters:
geometryGeometry or array_like

Geometry or geometries for which to compute the Delaunay triangulation.

tolerancefloat or array_like, default 0.0

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

only_edgesbool or array_like, default False

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

**kwargs

See NumPy ufunc docs for other keyword arguments.

Returns:
GeometryCollection or array of GeometryCollections

Examples

>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Polygon
>>> points = MultiPoint([(50, 30), (60, 30), (100, 100)])
>>> shapely.delaunay_triangles(points).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(points, only_edges=True)
<MULTILINESTRING ((50 30, 100 100), (50 30, 60 30), ...>
>>> shapely.delaunay_triangles(
...     MultiPoint([(50, 30), (51, 30), (60, 30), (100, 100)]),
...     tolerance=2
... ).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(Polygon([(50, 30), (60, 30), (100, 100), (50, 30)])).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(LineString([(50, 30), (60, 30), (100, 100)])).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(GeometryCollection([]))
<GEOMETRYCOLLECTION EMPTY>