Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a polygon is a multipolygon in Shapely

Tags:

How can I check if a polygon entity is actually a multipolygon? I've tried:

if len(polygon) > 1:

but then get the error:

TypeError: object of type 'Polygon' has no len()

I've tried Nill, None and others, nothing worked.

like image 352
Yair Avatar asked Aug 25 '16 10:08

Yair


1 Answers

Use the object.geom_type string (see general attributes and methods).

For example:

if poly.geom_type == 'MultiPolygon':
    # do multipolygon things.
elif poly.geom_type == 'Polygon':
    # do polygon things.
else:
    # raise IOError('Shape is not a polygon.')
like image 160
jmsinusa Avatar answered Sep 22 '22 11:09

jmsinusa