[QGIS-Developer] Is it possible to access the persistent spatial index (.qix file) through PyQGIS?

Luis Eduardo luis3176 at yahoo.com
Thu Jan 14 12:35:16 PST 2021


I built a manual index on a shapefile, through the process "Create spatial index", which can be found in the process toolbox > general vector tools. This process creates a persistent spatial index, a .quix file.

I want to optimize spatial queries on layers that have more than 300,000 records

Creating the spatial index with PyQGIS takes a little more than 6 seconds, as you can see in the code

pry=QgsProject.instance()parcelas=pry.mapLayersByName('parcelas')[0]radios=pry.mapLayersByName('radios_censales')[0]
tiempo_inicial = time.time()index = QgsSpatialIndex() # Spatial indexindex = QgsSpatialIndex(parcelas.getFeatures())duracionSI=time.time()-tiempo_inicial  #  6.816403388977051 sec
But what I really want to do use leverage the existing .qix file directly, How can I do this from PyQGIS?

Note: I am aware that the spatial index file must be updated if geometries are modified, removed or added.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210114/54d025f3/attachment.html>


More information about the QGIS-Developer mailing list