How do I amend the following python code: that determines the number of sides/edges of a polygon; to account for MultiPolygons? ---interiors aren't necessary. exteriors only please.
Without looping would be appreciated.
Data can be found here
edges = fp.geometry.apply(lambda x: len(x.exterior.coords)) - 1
edges
0 5
1 4
2 4
3 4
Name: geometry, dtype: int64
You can check if the geometry is an instance of
MultiPolygonand if so convert theMultiPolygonto a list ofPolygons, calculate the number of edges for each, and thensumthe total:You might also consider using
shapely.get_num_pointsandshapely.get_partsso your code is more explicit in what it is doing: