Book Image

QGIS Python Programming Cookbook

Book Image

QGIS Python Programming Cookbook

Overview of this book

Table of Contents (16 chapters)
QGIS Python Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 with the footprint of the main building.

Getting ready

You can download the building files from https://geospatialpython.googlecode.com/svn/union.zip and extract them to a directory named /qgis_data/union.

How to do it...

All we need to do is run the qgis:union algorithm, as follows:

  1. Start QGIS.

  2. From the Plugins menu, select Python Console.

  3. Import the processing module:

    import processing
    
  4. Now, run the algorithm by specifying the two input shapes and a single output file:

    processing.runandload("qgis:union","/qgis_data/union/building.shp","/qgis_data/union/walkway.shp","/qgis_data/union/union.shp")
    

How it works...

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...