Select points within polygons i can't for the life of me get it to work

271
4
04-10-2024 02:04 AM
StuartMoore
Occasional Contributor III

help, i have two datasets a FGDB with a polygon feature class containing over 350k polygons and a csv file with an xy point of a little over 275k records.

using Arcgis api for python (on a computer that doesn't have any ESRI software like Pro or Desktop) i've successfully read the polygons into a spatial dataframe and read the csv file also into a spatial dataframe

but when i try and identify which points intersect the polygons i get this error:

StuartMoore_0-1712739796897.jpeg

i have tried a few other ways but non seem to work, even the documentation doesn't seem to help

 

any ideas?

 

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

Most likely that the points and polygons are in different coordinate systems and the extents don't overlap (last error message) . If this is the case, the csv needs to be converted with a know coordinate system to something that the coordinate systems are know and/or the same


... sort of retired...
0 Kudos
StuartMoore
Occasional Contributor III

Hi Dan, thanks for that, i checked and both have the same coordinate system with then wkid of 27700.

from manually doing the intersection in Pro on another computer around 260k of the points fall within polygons

 

i did also try this method i found on another post and this looks more promising but flags some geometry issues which i need to work out how to fix...

StuartMoore_0-1712750400174.jpeg

 

0 Kudos
Clubdebambos
Occasional Contributor III

Hi @StuartMoore 

You could use spatial join.

# Load point and polygon spatial dataframes
points_gdf = gpd.read_file('path_to_points.shp')
polygons_gdf = gpd.read_file('path_to_polygons.shp')

# Perform spatial join
intersection = gpd.sjoin(points_gdf, polygons_gdf, how="inner", op='intersects')

# intersection dataframe will contain points that intersect with polygons
print(intersection)
~ learn.finaldraftmapping.com
0 Kudos
StuartMoore
Occasional Contributor III

thanks i tried that but thats where i was getting the geometry issues

0 Kudos