I would like to loop over all layers within a QGIS project and determine which layer don't have a spatial index and cause QGIS to slow down.
I tried the method
hasSpatialIndex() but this always returns
SpatialIndexUnknown even if it's for example a shapefile with qix file present in the same folder (created from QGIS itself).
source = iface.activeLayer() if source.hasSpatialIndex() == QgsFeatureSource.SpatialIndexNotPresent: print("not present") elif source.hasSpatialIndex() == QgsFeatureSource.SpatialIndexUnknown: print("unknown") elif source.hasSpatialIndex() == QgsFeatureSource.SpatialIndexPresent: print ("present") else: print ("something else")
I guess it's a bug that QGIS does not recognize the qix files in the same folder where the shapefiles are stored?
Is there really no PyQGIS-method to check layers if they are indexed? I am pretty sure that QGIS itselfs checks the existence of a spatial index because it uses the spatial index automatically if it exists.