2

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.

3
  • 1
    Try using PtDistWithin(GEOMETRY, MakePoint(0, 0, 4326), 150000)
    – Mike T
    Commented Jul 7, 2015 at 2:02
  • That is a faster query, but not using the index according to STRACE. The problem is I'm going to look for points within polycons as well as Circles. Commented Jul 7, 2015 at 3:25
  • If GDAL is using Spatialite SQL engine it may be that it can't utilize the .qix index because the native rtree index that Spatialite is using is so different. You can perhaps test if by looking at the strace with the default OGR SQL dialect with some supported query. A workaround would be to convert data from shapefiles into Spatialite db.
    – user30184
    Commented Jul 7, 2015 at 6:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.