<html><head></head><body><div class="yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div dir="ltr" data-setdir="false"><div><div>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.<br></div></div><br></div><div dir="ltr" data-setdir="false"><span>I want to optimize spatial queries on layers that have more than 300,000 records</span><br></div><div dir="ltr" data-setdir="false"><span><br></span></div><div dir="ltr" data-setdir="false"><span><span>Creating the spatial index with PyQGIS takes a little more than 6 seconds, as you can see in the code</span><br></span></div><div dir="ltr" data-setdir="false"><span><span><br></span></span></div><div dir="ltr" data-setdir="false"><span><div><div>pry=QgsProject.instance()</div><div>parcelas=pry.mapLayersByName('parcelas')[0]</div><div>radios=pry.mapLayersByName('radios_censales')[0]</div><div><br></div><div>tiempo_inicial = time.time()</div><div>index = QgsSpatialIndex() # Spatial index</div><div>index = QgsSpatialIndex(parcelas.getFeatures())</div><div>duracionSI=time.time()-tiempo_inicial # 6.816403388977051 sec</div></div><div><br></div><div dir="ltr" data-setdir="false"><span>But what I really want to do use leverage the existing .qix file directly, <span>How can I do this from PyQGIS?</span></span><br></div><div dir="ltr" data-setdir="false"><span><span><br></span></span></div><div dir="ltr" data-setdir="false"><span><span><span>Note: I am aware that the spatial index file must be updated if geometries are modified, removed or added.</span><br></span></span></div></span></div></div></body></html>