geopandas.GeoSeries.union_all#
- GeoSeries.union_all(method='unary')[source]#
Returns a geometry containing the union of all geometries in the
GeoSeries
.By default, the unary union algorithm is used. If the geometries are non-overlapping (forming a coverage), GeoPandas can use a significantly faster algorithm to perform the union using the
method="coverage"
option.- Parameters:
- methodstr (default
"unary"
) The method to use for the union. Options are:
"unary"
: use the unary union algorithm. This option is the most robust but can be slow for large numbers of geometries (default)."coverage"
: use the coverage union algorithm. This option is optimized for non-overlapping polygons and can be significantly faster than the unary union algorithm. However, it can produce invalid geometries if the polygons overlap.
- methodstr (default
Examples
>>> from shapely.geometry import box >>> s = geopandas.GeoSeries([box(0, 0, 1, 1), box(0, 0, 2, 2)]) >>> s 0 POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0)) 1 POLYGON ((2 0, 2 2, 0 2, 0 0, 2 0)) dtype: geometry
>>> s.union_all() <POLYGON ((0 1, 0 2, 2 2, 2 0, 1 0, 0 0, 0 1))>