This question already has an answer here:

I'm trying to determine which of about 300,000 points fall within any of 215 closed polygons. My code right now loops through each point and then through each shape to see if it the point is contained within a polygon.

def in_shapes(proj):
for i in range(len(shapes)):
    if Point(proj).within(shape(shapes[i])):
        return records[i][0]
return 'None'

df['ContainedIn'] = df.apply(lambda b: in_shapes(b.Projection), axis=1)

This works, but it is extremely time-consuming. Is there a more efficient way of determining:

  1. Which of a set of polygons a point falls within?
  2. Which of a list of points falls within a polygon?
  3. Or anything better?

marked as duplicate by Aaron Jan 10 at 4:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.