shapely.unary_union#

unary_union(geometries, grid_size=None, axis=None, **kwargs)#

Returns the union of multiple geometries.

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.

If grid_size is nonzero, input coordinates will be snapped to a precision grid of that size and resulting coordinates will be snapped to that same grid. If 0, this operation will use double precision coordinates. If None, the highest precision of the inputs will be used, which may be previously set using set_precision. Note: returned geometry does not have precision set unless specified previously by set_precision.

unary_union is an alias of union_all.

Parameters
geometriesarray_like
grid_sizefloat, optional

Precision grid size; requires GEOS >= 3.9.0. Will use the highest precision of the inputs by default.

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

For other keyword-only arguments, see the NumPy ufunc docs.

See also

union
set_precision

Examples

>>> from shapely import box, LineString, normalize, Point
>>> line1 = LineString([(0, 0), (2, 2)])
>>> line2 = LineString([(2, 2), (3, 3)])
>>> union_all([line1, line2])
<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>
>>> union_all([[line1, line2, None]], axis=1).tolist()
[<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>]
>>> box1 = box(0, 0, 2, 2)
>>> box2 = box(1, 1, 3, 3)
>>> normalize(union_all([box1, box2]))
<POLYGON ((0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0, 0 0))>
>>> box1 = box(0.1, 0.2, 2.1, 2.1)
>>> union_all([box1, box2], grid_size=1)
<POLYGON ((2 0, 0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0))>
>>> union_all([None, Point(0, 1)])
<POINT (0 1)>
>>> union_all([None, None])
<GEOMETRYCOLLECTION EMPTY>
>>> union_all([])
<GEOMETRYCOLLECTION EMPTY>