I have a set of ~36,000 polygons which represent a partition (~counties) of the country. My python script receives a lot of points: pointId, longitude, latitude.
For
It's great,
Here is sample code :
polygons_sf = shapefile.Reader("")
polygon_shapes = polygons_sf.shapes()
polygon_points = [q.points for q in polygon_shapes ]
polygons = [Polygon(q) for q in polygon_points]
idx = index.Index()
count = -1
for q in polygon_shapes:
count +=1
idx.insert(count, q.bbox)
[...]
for j in idx.intersection([point.x, point.y]):
if(point.within(polygons[j])):
geo1, geo2 = polygons_sf.record(j)[0], polygons_sf.record(j)[13]
break
Thanks