I'm trying to make a spatial verification.

I have a geodataframe with 245 points, and I'm having a bad time trying to check if they're inside a polygon or not.

I've been attempting this code, but I just won't work. As far as I understood, geodataframes are slightly different from dataframes when in a for loop.

for x in event_log_c.geometry:
    i = event_log_c.iloc[x].within(hexa)

After running this, it brings me this error:

TypeError: Cannot index by location index with a non-integer key

hexa is the polygon geodataframe, and event_log_c is the 245 points geodataframe.

How can I make a spatial verification iterating a geodataframe? Are there any way of doing this?

  • My disired result is a simple "True" or "False" output for each row. Commented Apr 23, 2021 at 13:27
  • 1
    There are many answers to this question in GSE; This answer for example, without loop.
    – gene
    Commented Apr 23, 2021 at 13:27
  • Thanks, Gene, but It wasn't what I was looking for. Luckly I found something that might fit well to me. I appreciate your help Commented Apr 23, 2021 at 13:48
  • This post helped me solve my problem Commented Apr 23, 2021 at 14:06