Given a Shapely MultiPolygon, how can I extract the biggest Polygon?
For example, given a MultiPolygon as follows:
from shapely.geometry import Polygon, MultiPolygon
multipolygon = MultiPolygon([Polygon([(0,0), (1,0), (1,0.25), (1, 0.5), (1,0.75), (1,1), (0,1)]),
Polygon([(2,0), (1.2,0.25), (1.2,0.25), (1.2,0.75), (2,0.75)])])
How can I get just the largest part?
Best Answer
Here's what I would do:
The built-in max function used this way will return the item from the list where
lambda a: a.area
is maximized.