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, band number, compute edges option, zevenbergen option for smoother terrain, z-factor elevation exaggeration number, scaling ratio of vertical to horizontal units, azimuth (angle of the light source), altitude (height of the light source), and output image's name:
    processing.runandload("gdalogr:hillshade", rasterLyr, 1, False, False, 1.0, 1.0, 315.0, 45.0, "/qgis_data/rasters/hillshade.tif")
    
  6. Verify that the output image, hillshade.tif, looks similar to the following image in QGIS. It should be automatically loaded into QGIS via the processing.runandload() method:
    How to do it...

How it works...

The Hillshade algorithm simulates a light source over an elevation dataset to make it more visually appealing. Most of the time, the only variables in the algorithm you need to alter are the z-factor, azimuth, and altitude to get different effects. However, if the resulting image doesn't look right, you may need to alter the scale. According to the GDAL documentation, if your DEM is in degrees, you should set a scale of 111120, and if it is in meters, you should set a scale of 370400. This dataset covers a small area such that a scale of 1 is sufficient. For more information on these values, see the gdaldem documentation at http://www.gdal.org/gdaldem.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset