shapely.coverage_union_all

shapely.coverage_union_all#

coverage_union_all(geometries, axis=None, **kwargs)#

Return the union of multiple polygons of a geometry collection.

This is an optimized version of union which assumes the polygons to be non-overlapping.

This function ignores None values when other Geometry elements are present. If all elements of the given axis are None, an empty GeometryCollection is returned (before GEOS 3.12 this was an empty MultiPolygon).

Parameters:
geometriesarray_like

Geometries to merge/union.

axisint, optional

Axis along which the operation is performed. The default (None) performs the operation over all axes, returning a scalar value. Axis may be negative, in which case it counts from the last to the first axis.

**kwargs

See NumPy ufunc docs for other keyword arguments.

See also

coverage_union

Notes

Deprecated since version 2.1.0: A deprecation warning is shown if axis 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 Polygon
>>> polygon_1 = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
>>> polygon_2 = Polygon([(1, 0), (1, 1), (2, 1), (2, 0), (1, 0)])
>>> shapely.coverage_union_all([polygon_1, polygon_2]).normalize()
<POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))>
>>> shapely.coverage_union_all([polygon_1, None]).normalize()
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
>>> shapely.coverage_union_all([None, None]).normalize()
<GEOMETRYCOLLECTION EMPTY>