6

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?

7
  • 1
    ArcGIS has a similar bug when loading data via ArcSDE; its a result of bad data and ArcSDE not being able to handle it. Might that be the case here? --- Might be worth reporting this one as a bug to the QGIS folks and uploading the SpatiaLite database: hub.qgis.org/projects/quantum-gis/issues/new Commented Oct 31, 2012 at 10:13
  • @GIS_Jonathan: Can you describe what was "bad" in the data you refer to?
    – AndreJ
    Commented Oct 31, 2012 at 12:04
  • did you check your shape-file: is it perfectly valid? you may also want to check the shp with openjump-gis, which has very strict checks
    – Kurt
    Commented Oct 31, 2012 at 12:12
  • @Kurt: I checked spatialite and exported shapefile layers in qgis and they were all right. I didn't check with Openjump, because I am new to GIS and the only program I am familiar with is Qgis. By the way, can Openjump work with Sptialite layers? Commented Nov 1, 2012 at 1:12
  • @GIS-Jonathan: I added my data in the above post, would you mind have a look? Commented Nov 1, 2012 at 1:14

2 Answers 2

10

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.

4
  • This one looks to be it. I tested the data and there's nothing wrong there, so I used FME to copy from the Spatialite file to a new one (with new spatial indexes) and the test data works fine. Commented Nov 1, 2012 at 10:43
  • Windows users can get precompiled binaries of the gui from: gaia-gis.it/gaia-sins/windows-bin-amd64 or gaia-gis.it/gaia-sins/windows-bin-x86
    – AndreJ
    Commented Nov 1, 2012 at 12:58
  • thanks to Stev_k for this very valueable solution of a nasty problem. @Cao Minh Tu: if you can resolve this too following Stev_ks solution, you should accept his solution
    – Kurt
    Commented Nov 1, 2012 at 22:17
  • It works! I use spatialite-gui v1.2.1 from ubuntugis-unstable ppa - it have no menu item "Check Spatial Index", so I select "Remove Spatial Index" and build again. Thanks a lot, Stev_k and all of you guys. This is the greatest community I've join so far. Commented Nov 2, 2012 at 1:13
3

First check are the geometries valid. In some basic cases invalid geometries are rendered but in some not - very often so happens with geometries imported from CAD formats (no matter how it is done using ArcGIS or ogr2ogr both solutions have some weak interpreted cases). If there is allowed data repairing you can import in GRASS GIS and then export to shapes and back to sqlite - so you can escape from manual repair. In a lot of cases helps immediately :)

1
  • I checked the geometries and they were all valid. The problem may go away if I export and re-import data (I did this several times). The problem is I can't tell the colleagues I am training to work with Qgis and spatialite to do the same - as they have no knowledge in GIS, this will be too much work for them. And what if the problem appear again several times in their work process? This will be too much pain for them (and for me too). Commented Nov 1, 2012 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.