[GIS] Why is this spatialite polygon layer not displayed properly

qgisspatialite

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:

  1. Vietnam map at zoom level 1:16000000 – some provinces missing in the northern part creating holes.
    enter image description here

  2. Scroll mouse wheel to zoom closer one level (1:8000000). The northern most province in the view is missing.
    enter image description here

  3. Zoom closer to the southern part.
    enter image description here

  4. Moving one step closer. The large number of missing polygons make it hard to mark all of them with circles.
    enter image description here

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.

Test data

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 select Check 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.

enter image description here

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.