Using osgeo's Python API for OGR, I'd like to implement the following process:
- Import ESRI Shapefiles from a given directory (call it
input_dir
) - Import a CSV file that contains lat-longs of interest (call it
poicsv
) - Join the CSV file long, lats with the Shapefile layer and extract the feature attribute values for that long, lat
I am currently up to the step where I have a single Shapefile loaded, and the CSV file loaded with long/lats in a list of tuples (ie. [(-123.76073, 41.24946), (-123.84451, 41.24946), ...]). Per long lat, I am trying to use SetSpatialFilter on the layer by the following code:
for ll in longlat:
point = ogr.Geometry(ogr.wkbPoint)
point.AddPoint_2D(ll[0], ll[1])
layer.SetSpatialFilter(point)
for feat in layer:
feat.items()
However, upon sanity checking I've noticed there is no API for removing the Spatial Filter in my for loop, and I am also concerned about the memory leak created by creating a wkbPoint through the ogr.Geometry function in every iteration. Will the point object be cleaned up every iteration, and how could I reset the Spatial Filter every iteration?