mee
mee

Reputation: 708

Convert multipolygon geometry into list

How can I please convert a multipolygon geometry into a list? I tried this:

mycoords=geom.exterior.coords
mycoordslist = list(mycoords)

But I get the error:

AttributeError: 'MultiPolygon' object has no attribute 'exterior'

Upvotes: 7

Views: 15311

Answers (2)

Khaos101
Khaos101

Reputation: 452

The error raise simply because you are trying to get coordinates from the wrong attribute, exterior is an attribute of Polygon, not of MultyPolygon.

This could work:

mycoordslist = [poly.exterior.coords for poly in list(geom)]

Upvotes: 1

martinfleis
martinfleis

Reputation: 7804

You will have to loop over geometries within your MultiPolygon.

mycoordslist = [list(x.exterior.coords) for x in geom.geoms]

Note that the result is a list of coords lists.

Upvotes: 14

Related Questions