How to find containing Polygon within a shapely MultiPolygon

Viewed 90

In shapely, a MultiPolygon is made of several disjoint Polygons (except one-point intersections). If I have a MultiPolygon polys and a Point pt, then I can test for containment by

polys.contains(pt)

which gives True in case the point is in at least one of the polygons. I assume this is working efficiently on the inside by using some R-Tree. However, actually, I am interested, in which of the Polygons in the MultiPolygon the Point is contained. I wonder, whether there is a trick to identify it without testing through the list of polygons (i.e., polys.geoms)?

Any hint is appreciated - thanks already!!

1 Answers

You could always use the syntax

for poly in polys.geoms:
    if poly.contains(pt):
        print(poly)
Related