3

I have shapely multipolygon, how can I convert that to list of polygons?

polygons = [Polygon(cham_geom), Polygon(neighbor_geom)]
boundary = cascaded_union(polygons)  # results in multipolygon sometimes
if boundary.geom_type == 'MultiPolygon':
       # extract polygons out of multipolygon
Atihska
  • 4,803
  • 10
  • 56
  • 98

1 Answers1

3

MultiPolygon is iterable via geoms attribute, so you can do for loop over polygons within multipolygon.

polygons = [Polygon(cham_geom), Polygon(neighbor_geom)]
boundary = cascaded_union(polygons)  # results in multipolygon sometimes
if boundary.geom_type == 'MultiPolygon':
   # extract polygons out of multipolygon
   list = []
   for polygon in boundary.geoms:
       list.append(polygon)
martinfleis
  • 7,124
  • 2
  • 22
  • 30