[GIS] QGIS how to enable spatial indexes on Spatialite table

qgisspatialite

I've created a Spatialite layer with all of the waterbodies and watercourses in Saskatchewan for use in QField. Rendering is quite slow on both my older laptop and my field device – a G5 cell phone. When I look at the layer properties I see that the "create spatial index" button is disabled.

I know that Spatialite supports spatial indexes, but it's not clear from what I've read whether the newer virtual spatial index is created automatically or if I need to enable it somehow. If it is truly virtual then I assume it is created on the fly, which would be a bad thing in the case of QField. It's also not clear whether QField will use spatial indexes but that's a question for a different forum.

Best Answer

After lots of messing around I've determined that the spatial indexes are indeed there and can be created when the table is being created, quite simply. In my case I used Save as to save a selection as a new Spatialite table and 'create spatial index' is an option.

In a current version of spatialite-gui you can see the Spatial Index within the structure of the Spatialite file - not the table itself, although there are table specific indexes within it.

I specified the current version of the gui utility because there are a number of downloads available of older versions, which is where I went wrong the first time. Choose the appropriate link here (https://www.gaia-gis.it/gaia-sins/index.html) to get the current version.

Related Question