geopandas.GeoSeries.union_all#

GeoSeries.union_all(method='unary', *, grid_size=None)[source]#

Return 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. Alternatively, for situations which can be divided into many disjoint subsets, method="disjoint_subset" may be preferable.

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.

  • "disjoint_subset:: use the disjoint subset union algorithm. This option is optimized for inputs that can be divided into subsets that do not intersect. If there is only one such subset, performance can be expected to be worse than "unary". Requires Shapely >= 2.1.

grid_sizefloat, default None

When grid size is specified, a fixed-precision space is used to perform the union operations. This can be useful when unioning geometries that are not perfectly snapped or to avoid geometries not being unioned because of robustness issues. The inputs are first snapped to a grid of the given size. When a line segment of a geometry is within tolerance off a vertex of another geometry, this vertex will be inserted in the line segment. Finally, the result vertices are computed on the same grid. Is only supported for method "unary". If None, the highest precision of the inputs will be used. Defaults to None.

Added in version 1.1.0.

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))>