In QGIS, I have a spatialite multipolygon layer that have full objects in attribute table but do not display random ones as I scroll and pan around:
-
Vietnam map at zoom level 1:16000000 – some provinces missing in the northern part creating holes.
-
Scroll mouse wheel to zoom closer one level (1:8000000). The northern most province in the view is missing.
-
Zoom closer to the southern part.
-
Moving one step closer. The large number of missing polygons make it hard to mark all of them with circles.
When I pan around, the polygons may re-appear at some places and disappear at some others. If I export this layer as shapefile and add to the map, there is no missing polygon at all.
Does anyone know how to fix this?
Best Answer
This is a problem with the spatial index, not the data itself. You can check this by opening the file in
spatialite-gui
(available from https://www.gaia-gis.it/fossil/spatialite_gui/home) and right click on the geometry layer then selectCheck Spatial Index
. It should say it is malformed / corrupted. You can then remove the index by right clicking again.The layer then works correctly in QGIS.
Graphic below.
As an aside, to avoid this problem happening in the future it would be very useful if you could detail exactly how the spatialite file was built (if you know). Or give a sample of the shapefile used to build. I can then pass this on to the Spatialite developers who may be able to fix that. Alternatively, it could be something that happened to the file in the period since the shapefile data was converted.