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 an elevation hillshade


A hillshade, or shaded relief, is a technique to visualize elevation data in order to make it photorealistic for presentation as a map. This capability is part of GDAL and is available in QGIS in two different ways. It is a tool in the Terrain Analysis menu under the Raster menu and it is also an algorithm in the Processing Toolbox.

Getting ready

You will need to download a DEM from https://geospatialpython.googlecode.com/files/dem.zip.

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 the DEM layer and run the Hillshade processing algorithm against it. 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 layer:

    rasterLyr = QgsRasterLayer("/qgis_data/rasters/dem.asc", "Hillshade")
    rasterLyr.isValid()
    
  5. Run the Hillshade algorithm, providing the algorithm name, layer reference...