Performing a union on vector shapes
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 to the footprint of the main building.
Getting ready
You can download the building files from the following URL and extract them to a directory named /qgis_data/union
:
https://github.com/GeospatialPython/Learn/raw/master/union.zip
How to do it...
All we need to do is run the qgis:union
algorithm:
- Start QGIS.
- From the Plugins menu, select Python Console.
- Import the
processing
module:import processing
- Now, run the algorithm specifying the two input shapes and the single output file:
processing.runandload("qgis:union", "/qgis_data/union/building.shp", ...
Get QGIS Python Programming Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.