# Converting Shapely MultiPolygon to Polygon: Technique doesn't always work

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]
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?

Can it be the holes in the polygon? I looks like this: • A MultiPolygon is a simple list of Polygons, therefore a lists has not "exterior", but every Polygon in the list has "exterior". If you want the Polygons use a for loop ([p.exterior.xy for p in Multi)] – gene Feb 10 '16 at 9:34
• Okay, I see, but what can I do then in order to get the exterior coordinates of the MultiPolygon? In my approach I am trying a union of the single polygons, but this seems to be not working here.... – countryman Feb 10 '16 at 9:49
• Is it possible that the API of shapely changed in the mean time? I don't see the attribute `geometry` in a `Polygon`, but `geom_type` ? – K.-Michael Aye Jan 11 '18 at 8:29

You need to understand the Shapely binary predicates:

1) If the two polygons intersects the result of `union` or `unary_union` (in red) is a Polygon therefore you can computes the exterior

2) If the two polygons are disconnected, the result is necessary a MultiPolygon (in red with two polygons)

And if you work with Shapefiles, without topology, this may occur

A solution is to compute the Concave Hull but it is not really an union. • Okay, indeed, I found out that this is the case - and logic! Thanks a lot! – countryman Feb 12 '16 at 14:58
• how do you compute concave hull? – Dima Lituiev May 10 '18 at 19:48