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

Dissolving vector shapes


Dissolving shapes can take two different forms. You can combine a group of adjoining shapes by the outermost boundary of the entire dataset, or you can also group the adjoining shapes with the same attribute value.

Getting ready

Download the GIS census tract shapefile, which contains tracts for several counties from https://geospatialpython.googlecode.com/files/GIS_CensusTract.zip.

Extract it to your /qgis_data directory, in a directory called census.

How to do it...

We will use the Processing Toolbox for this recipe and specifically a native QGIS algorithm called dissolve, as follows:

  1. Start QGIS.

  2. From the Plugins menu, select Python Console.

  3. Import the processing module:

    import processing
    
  4. Next, run the dissolve algorithm, specifying the input data—False to specify that we don't want to dissolve all the shapes into one but to use an attribute instead—the attribute we want to use, and the output filename:

    processing.runandload("qgis:dissolve","/qgis_data/census/GIS_CensusTract_poly...