In order to get the exterior coordinates I need to convert a shapely MultiPolygon to a Polygon. I do it like this:
if poly.geometry.type == 'Polygon': x, y = poly.geometry.exterior.xy elif poly.geometry.type == 'MultiPolygon': allparts = [p.buffer(0) for p in poly.geometry] poly.geometry = shapely.ops.cascaded_union(allparts) x, y = poly.geometry.exterior.xy # here happens the error
This succeeds very often, but there are also cases where the Polygon obviously stays a MultiPolygon as the following error is still raised:
AttributeError: 'MultiPolygon' object has no attribute 'exterior'
I've checked, however, that every part of the MultiPolygon is a polygon and not itself a MultiPolygon:
>>>>[p.type for p in poly.geometry] ['Polygon', 'Polygon']
Any ideas why this happens and how to fix it?