[GIS] Losing features when merging vector layers in QGIS

mergeqgis

Trying the v.clean command and checked the layer with Topology checker and it turned out every single geometry was invalid.

What to do now?

enter image description here


Original question:

I have two shapefiles with 3D building blocks that I want to merge (Both MultiPolygonZ-type, the same columns in attribute table with the same projection). The blocks represent houses in two different area of the city (no overlaps).

Vector > Data Management Tools > Merge vector layers works great except that some features in the merged file looses it's solidness, see example below:

Houses from one of the shapes before merge (all houses are solid):

enter image description here

The same canvas from the merged file (some features loose their solidness):
enter image description here

Has anyone experienced the same problem and been able to workaround it?

Links below to two of the shape-files I'm trying to merge if anyone want to try and re-create the problem:

Dataset A: https://drive.google.com/open?id=0BwFHJFrNX33hbGFHS2ZCeUVJNWc

Dataset B: https://drive.google.com/open?id=0BwFHJFrNX33hZGFoT2xiVXZSbGs

Best Answer

I had the same issue dossolving polygons, the problem was that there were Geometry Errors. Bare in mind my process was a Standalone application, however the concept should help. Before performing the merge I ran

validate= processing.runalg("grass7:v.clean",CleanedOutput,0,0.1,extents,-1,0.0001,InFeature,errorsOutput)

This tool is simply a GRASS tool called v.clean, you can search for it from your processing toolbox. This tool cleans the geometry of the input vector layer, read about this more HERE

The different types of v.clean

If you don't trust the v.clean to solv the problems, You can also use the Check Geometry Validity from fTools plugin, to inspect the file manually, this tool will highlight all geometry errors, enter edit mode to solve the errors by deleting duplicate Nodes, Polygon overlaps etc.

Once the Geometry errors are dealt with the files should merge, dissolve, intersect, without losing features.

Another method I used was the GDAL tools ogr2ogr

To create a file to merge into use the following command. This will take a shapefile and copy it to a file called merge.shp (this filename is up to you).

ogr2ogr -f ‘ESRI Shapefile’ merge.shp filename1.shp
Then merge the following files by using:

ogr2ogr -f ‘ESRI Shapefile’ -update -append merge.shp filename2.shp -nln merge
ogr2ogr -f ‘ESRI Shapefile’ -update -append merge.shp filename3.shp -nln merge

read more here

*Note you need the OSGeo4W shell provided with the For Advanced Users Download * This should help defeat the geometry errors Hopefully this solves your issue, I remember how frustrating it was with me.

Related Question