I created a spatial index foo.qix for a foo.shp with ogrinfo -sql "CREATE SPATIAL INDEX ON foo" foo.shp
However, when I do a query with ogr2ogr and look at it in strace, it doesn't use that index:
strace -e open,access /opt/gdal-custom/bin/ogr2ogr -f CSV /vsistdout/ foo.shp -dialect sqlite -sql "SELECT * FROM foo WHERE ST_Intersects(GEOMETRY,BuildCircleMbr(0, 0, 150000, 4326))" 2>&1 | grep foo
open(" foo.shp", O_RDONLY) = 3
open(" foo.shx", O_RDONLY) = 4
open(" foo.dbf", O_RDONLY) = 4
open(" foo.cpg", O_RDONLY) = -1 ENOENT (No such file or directory)
open(" foo.CPG", O_RDONLY) = -1 ENOENT (No such file or directory)
open(" foo.prj", O_RDONLY) = 5
Once I get this working, if there is a speed improvement, I'd also like to apply spatial index to a similar query from python via ExecuteSQL on the shapefile.
PtDistWithin(GEOMETRY, MakePoint(0, 0, 4326), 150000)