I would like to store an r-tree or quadtree index in a sqlite database using python.

Does anyone know if there is any code to do this?

A bit of background:

  • The dataset cannot be moved to another format.
  • the dataset in question is a shapefile
  • Though there is spatial indexing for shapefiles, it's not meeting the needs
  • I want to avoid using spatialite extension (it's messy to install on windows)

I can create a quadtree/rtree in-memory, but since the dataset is very large, the index takes a longtime to build. In addition, it consumes a large about of memory and effects other analysis down stream. If I could store the index in sqlite it would help get past that issue I think.

  • You seem to deal with quite special case. Easiest way that I can imagine is to convert you data into GeoPackage with ogr2ogr and then utilize just the r-tree index that gets created automatically. By using the -sql option it is possible to skip the attributes which makes conversion faster. – user30184 Jun 7 '18 at 19:54
  • I thought of this option, but like I stated, converting to GeoPackage is not an option. – code base 5000 Jun 8 '18 at 9:35
  • What's the problem with converting data into GeoPackage if you just do not use the geometry tables? You have .shp there and hopefully you can connect shapes with the row in index by the rowid. – user30184 Jun 8 '18 at 10:32
  • I don't want to waste the time copying the datasets. – code base 5000 Jun 8 '18 at 14:27
  • Have you measured how long it would take? Tell us what is acceptable and what is wrong with the native .shx index or the .qix index that GDAL can create. – user30184 Jun 8 '18 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.