Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
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 –  GIS-Jonathan Oct 31 '12 at 10:13
    
@GIS_Jonathan: Can you describe what was "bad" in the data you refer to? –  Andre Joost Oct 31 '12 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 Oct 31 '12 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? –  Cao Minh Tu Nov 1 '12 at 1:12
    
@GIS-Jonathan: I added my data in the above post, would you mind have a look? –  Cao Minh Tu Nov 1 '12 at 1:14

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
    
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. –  GIS-Jonathan Nov 1 '12 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 –  Andre Joost Nov 1 '12 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 Nov 1 '12 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. –  Cao Minh Tu Nov 2 '12 at 1:13

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 :)

share|improve this answer
    
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). –  Cao Minh Tu Nov 1 '12 at 1:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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