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

Converting a raster to a vector


Raster datasets represent real-world features efficiently but can have limited usage for geospatial analysis. Once you have classified an image into a manageable data set, you can convert those raster classes into a vector data set for more sophisticated GIS analysis. GDAL has a function for this operation called polygonize.

Getting ready

You will need to download the following classified raster and place it in your /qgis_data/rasters directory:

https://geospatialpython.googlecode.com/svn/landuse_bay.zip

How to do it...

Normally, you would save the output of this recipe as a shapefile. We won't specify an output file name. The Processing Toolbox will assign it a temporary filename and return that filename. We'll simply load the temporary file into QGIS. The algorithm allows you to write to a shapefile by specifying it as the last parameter.

  1. In the QGIS Python Console, import the processing module:

    import processing
    
  2. Next, run the algorithm specifying the process...