shapely.polygonize#
- polygonize(geometries, **kwargs)#
Creates polygons formed from the linework of a set of Geometries.
Polygonizes an array of Geometries that contain linework which represents the edges of a planar graph. Any type of Geometry may be provided as input; only the constituent lines and rings will be used to create the output polygons.
Lines or rings that when combined do not completely close a polygon will result in an empty GeometryCollection. Duplicate segments are ignored.
This function returns the polygons within a GeometryCollection. Individual Polygons can be obtained using
get_geometry
to get a single polygon orget_parts
to get an array of polygons. MultiPolygons can be constructed from the output usingshapely.multipolygons(shapely.get_parts(shapely.polygonize(geometries)))
.- Parameters:
- geometriesarray_like
An array of geometries.
- axisint
Axis along which the geometries are polygonized. The default is to perform a reduction over the last dimension of the input array. A 1D array results in a scalar geometry.
- **kwargs
See NumPy ufunc docs for other keyword arguments.
- Returns:
- GeometryCollection or array of GeometryCollections
See also
Examples
>>> from shapely import LineString >>> lines = [ ... LineString([(0, 0), (1, 1)]), ... LineString([(0, 0), (0, 1)]), ... LineString([(0, 1), (1, 1)]) ... ] >>> polygonize(lines) <GEOMETRYCOLLECTION (POLYGON ((1 1, 0 0, 0 1, 1 1)))>