geopandas.GeoDataFrame.explode

GeoDataFrame.explode(column=None, ignore_index=False, index_parts=None, **kwargs)

Explode muti-part geometries into multiple single geometries.

Each row containing a multi-part geometry will be split into multiple rows with single geometries, thereby increasing the vertical size of the GeoDataFrame.

Note

ignore_index requires pandas 1.1.0 or newer.

Parameters
columnstring, default None

Column to explode. In the case of a geometry column, multi-part geometries are converted to single-part. If None, the active geometry column is used.

ignore_indexbool, default False

If True, the resulting index will be labelled 0, 1, …, n - 1, ignoring index_parts.

index_partsboolean, default True

If True, the resulting index will be a multi-index (original index with an additional level indicating the multiple geometries: a new zero-based index for each single part geometry per multi-part geometry).

Returns
GeoDataFrame

Exploded geodataframe with each single geometry as a separate entry in the geodataframe.

See also

GeoDataFrame.dissolve

dissolve geometries into a single observation.

Examples

>>> from shapely.geometry import MultiPoint
>>> d = {
...     "col1": ["name1", "name2"],
...     "geometry": [
...         MultiPoint([(1, 2), (3, 4)]),
...         MultiPoint([(2, 1), (0, 0)]),
...     ],
... }
>>> gdf = geopandas.GeoDataFrame(d, crs=4326)
>>> gdf
    col1                                       geometry
0  name1  MULTIPOINT (1.00000 2.00000, 3.00000 4.00000)
1  name2  MULTIPOINT (2.00000 1.00000, 0.00000 0.00000)
>>> exploded = gdf.explode(index_parts=True)
>>> exploded
      col1                 geometry
0 0  name1  POINT (1.00000 2.00000)
  1  name1  POINT (3.00000 4.00000)
1 0  name2  POINT (2.00000 1.00000)
  1  name2  POINT (0.00000 0.00000)
>>> exploded = gdf.explode(index_parts=False)
>>> exploded
    col1                 geometry
0  name1  POINT (1.00000 2.00000)
0  name1  POINT (3.00000 4.00000)
1  name2  POINT (2.00000 1.00000)
1  name2  POINT (0.00000 0.00000)
>>> exploded = gdf.explode(ignore_index=True)
>>> exploded
    col1                 geometry
0  name1  POINT (1.00000 2.00000)
1  name1  POINT (3.00000 4.00000)
2  name2  POINT (2.00000 1.00000)
3  name2  POINT (0.00000 0.00000)