Skip to main content
added 263 characters in body
Source Link
Bera
  • 77.9k
  • 14
  • 78
  • 188

Explode.Explode:

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

The first row is a multipolygon with three parts.

import geopandas as gpd
df = gpd.read_file(r"C:\GIS\GIStest\multipolygons.shp")
df.plot(column="id", cmap="cool")

enter image description here

#df.head()
#    id                                           geometry
# 0   1  MULTIPOLYGON (((633399.839 7186225.194, 635561...
# 1   2  POLYGON ((640064.755 7186290.697, 640064.755 7...
# 2   3  POLYGON ((638721.946 7182507.908, 638721.946 7...
# 3   4  POLYGON ((633989.365 7187502.500, 633989.365 7...

exploded = df.explode()
# exploded.head()
#      id                                           geometry
# 0 0   1  POLYGON ((633399.839 7186225.194, 635561.434 7...
#   1   1  POLYGON ((636069.081 7186143.316, 637280.883 7...
#   2   1  POLYGON ((636232.838 7184571.247, 637575.646 7...
# 1 0   2  POLYGON ((640064.755 7186290.697, 640064.755 7...
# 2 0   3  POLYGON ((638721.946 7182507.908, 638721.946 7...

Explode. The first row is a multipolygon with three parts.

import geopandas as gpd
df = gpd.read_file(r"C:\GIS\GIStest\multipolygons.shp")
df.plot(column="id", cmap="cool")

enter image description here

#df.head()
#    id                                           geometry
# 0   1  MULTIPOLYGON (((633399.839 7186225.194, 635561...
# 1   2  POLYGON ((640064.755 7186290.697, 640064.755 7...
# 2   3  POLYGON ((638721.946 7182507.908, 638721.946 7...
# 3   4  POLYGON ((633989.365 7187502.500, 633989.365 7...

exploded = df.explode()
# exploded.head()
#      id                                           geometry
# 0 0   1  POLYGON ((633399.839 7186225.194, 635561.434 7...
#   1   1  POLYGON ((636069.081 7186143.316, 637280.883 7...
#   2   1  POLYGON ((636232.838 7184571.247, 637575.646 7...
# 1 0   2  POLYGON ((640064.755 7186290.697, 640064.755 7...
# 2 0   3  POLYGON ((638721.946 7182507.908, 638721.946 7...

Explode:

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

The first row is a multipolygon with three parts.

import geopandas as gpd
df = gpd.read_file(r"C:\GIS\GIStest\multipolygons.shp")
df.plot(column="id", cmap="cool")

enter image description here

#df.head()
#    id                                           geometry
# 0   1  MULTIPOLYGON (((633399.839 7186225.194, 635561...
# 1   2  POLYGON ((640064.755 7186290.697, 640064.755 7...
# 2   3  POLYGON ((638721.946 7182507.908, 638721.946 7...
# 3   4  POLYGON ((633989.365 7187502.500, 633989.365 7...

exploded = df.explode()
# exploded.head()
#      id                                           geometry
# 0 0   1  POLYGON ((633399.839 7186225.194, 635561.434 7...
#   1   1  POLYGON ((636069.081 7186143.316, 637280.883 7...
#   2   1  POLYGON ((636232.838 7184571.247, 637575.646 7...
# 1 0   2  POLYGON ((640064.755 7186290.697, 640064.755 7...
# 2 0   3  POLYGON ((638721.946 7182507.908, 638721.946 7...
Source Link
Bera
  • 77.9k
  • 14
  • 78
  • 188

Explode. The first row is a multipolygon with three parts.

import geopandas as gpd
df = gpd.read_file(r"C:\GIS\GIStest\multipolygons.shp")
df.plot(column="id", cmap="cool")

enter image description here

#df.head()
#    id                                           geometry
# 0   1  MULTIPOLYGON (((633399.839 7186225.194, 635561...
# 1   2  POLYGON ((640064.755 7186290.697, 640064.755 7...
# 2   3  POLYGON ((638721.946 7182507.908, 638721.946 7...
# 3   4  POLYGON ((633989.365 7187502.500, 633989.365 7...

exploded = df.explode()
# exploded.head()
#      id                                           geometry
# 0 0   1  POLYGON ((633399.839 7186225.194, 635561.434 7...
#   1   1  POLYGON ((636069.081 7186143.316, 637280.883 7...
#   2   1  POLYGON ((636232.838 7184571.247, 637575.646 7...
# 1 0   2  POLYGON ((640064.755 7186290.697, 640064.755 7...
# 2 0   3  POLYGON ((638721.946 7182507.908, 638721.946 7...