How to extract Polygons from Multipolygons in Shapely?

Rahul picture Rahul · Aug 13, 2016 · Viewed 21.6k times · Source

I'm trying to extract the polygons from multipolygons in Shapely. I can transform a list of polygons into multipolygons using MultiPolygon from Shapely.

>>> Multi = MultiPolygon([shape(pol['geometry']) for pol in fiona.open('data.shp')]) 

And,

>>> Multi.wkt
'MULTIPOLYGON (((249744.2315302934148349 142798.1643468967231456, 250113.7910872535139788 142132.9571443685272243, 250062.6213024436729029 141973.7622582934272941, 249607.7787708004761953 141757.7120557629095856, 249367.7742475979903247 142304.6840291862317827, 249367.7742475979903247 142304.6840291862317827, 249744.2315302934148349 142798.1643468967231456)), 
               ((249175.7899173096520826 142292.5352640640921891, 249367.7742475979903247 142304.6840291862317827, 249607.7787708004761953 141757.7120557629095856, 249014.4539607730694115 141876.1348429077770561, 249175.7899173096520826 142292.5352640640921891)))'

Does anybody know how can I reverse the process i.e. given a multipolygon how can I convert it to separate polygons?

Answer

Nbarjest picture Nbarjest · May 8, 2018

Simply do

Polygons = list(Multi)

This extracts the polygons and puts them in a list.