A union turns two overlapping shapes into one. This task can be easily accomplished with the Processing Toolbox. In this recipe, we'll merge the outline of a covered building with the footprint of the main building.
You can download the building files from https://geospatialpython.googlecode.com/svn/union.zip and extract them to a directory named /qgis_data/union
.
All we need to do is run the qgis:union
algorithm, as follows:
processing
module:import processing
processing.runandload("qgis:union","/qgis_data/union/building.shp","/qgis_data/union/walkway.shp","/qgis_data/union/union.shp")
As you can tell from the structure of the command, this tool can only combine two shapes at once. It finds where the two shapes meet and then removes the overlap, joining them at the meeting point.
In the original data, the shapefile starts out as two distinct shapes, as shown in this image:
Once the union is complete, the shapes are now one shapefile, with the overlap being a separate feature, as shown in this image: