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

Creating vector contours from elevation data


Contours provides an effective visualization of terrain data by tracing a line along the same elevation to form a loop at set intervals in the dataset. Similar to the hillshade capability in QGIS, the Contour tool is provided by GDAL both as a menu option under the Raster menu in the Extraction category as well as a Processing Toolbox algorithm.

Getting ready

This recipe uses the DEM from https://geospatialpython.googlecode.com/files/dem.zip, which is used in the other recipes as well.

Unzip the file named dem.asc and place it in your /qgis_data/rasters directory.

How to do it...

In this recipe, we will load and validate the DEM layer, add it to the map, and then produce and load the contour vector as a layer. To do this, we need to perform the following steps:

  1. Start QGIS.

  2. From the Plugins menu, select Python Console.

  3. Import the processing module.

    import processing
    
  4. Load and validate the DEM:

    rasterLyr = QgsRasterLayer("/qgis_data/rasters/dem.asc", "DEM...