QGIS – using contours to create a shaded relief

Creating a relief map is not something I have to do very often. Terrain rarely changes so unless the geographic scope or quality of the elevation datasets improve there is no real call to create relief data on a regular basis.

So when I needed to create a new shaded relief raster the other day it came as something of a shock that I couldn’t remember the process from the last time I had done it. Enter Google search engine and QGIS…

The easiest means of using QGIS to create a new shaded relief raster dataset from contours is through the GRASS (Geographic Resource Analysis Support System) plugin which is included in the QGIS install (using the Windows standalone installer) and the DEM relief shader plugin.

Step 1: create new GRASS mapset (Plugins > GRASS > New mapset)

The explanations about the data structure for a GRASS mapset are included in each step of the process but in short the ‘folder structure’ works like:

  • Database
    • Location
      • User 1 mapset
      • User 2 mapset
      • etc

Step 2 – add vector contour layer to QGIS (Layer > Add vector layer)

Step 3 – import vector layer into GRASS (Plugins > GRASS > Open GRASS tools > Modules List)

Use v.in.ogr.qgis to import the QGIS contour vector dataset into your GRASS mapset.

Step 4 – edit GRASS settings  (Plugins > GRASS > Edit Current GRASS Region)

It is important to ensure the geographical region you are working with is defined correctly so that any data processing is only confined to the area of interest and, therefore, speeding things up. Unless you happen to know the extent of your dataset and can type it in, click and drag on the QGIS canvas to define your area of interest.

Change the resolution so that the cell width and height match the contour interval of your data.

Step 5 – convert vector contours into raster (Plugins > GRASS > Open GRASS tools > Modules List)

Use v.to.rast.attr and set the attribute field to the elevation.


Raster contours

Step 6 – create a surface from the raster contours  (Plugins > GRASS > Open GRASS tools > Modules List)

Use r.surf.contour to create a surface. When the surface fist appears it will look pretty much like a large grey square. Select the layer then go to Layer > Properties > Style > Single band properties > Color map and change this to ‘Pseudocolor’ to get a better visual effect.



Step 7 – export surface to a geotiff  (Plugins > GRASS > Open GRASS tools > Modules List)

Use r.out.gdal.gtiff to output the surface to a geotiff that can be manipulated in QGIS. Choose the format based on the range of your data. I used UInt16 as this has a range of values from 0 to 65,535, there is no areas below sea level so a lower limit of 0 is fine and the data type Byte does not go high enough for some of the mountains in the area of interest.

Step 8 – create a shaded relief (Plugins > Shaded Relief > Shaded Relief)

Select the geotiff surface in the layers list to make it the active layer before opening the DEM relief shader tool. Simply leave all the settings as per the defualts and click OK. The output file will be written to the same location as the surface file.

Shaded relief

Shaded relief

And there is your relief map!

Useful References:




  1. Thanks for the guide – have been trying this all morning but QGIS 1.9 dev keeps crashing at Step 5 with the raster conversion. When I re-open the GRASS database I can see the new raster layer and there’s metadata that indicates *something* happened, but I can’t see it on the canvas and trying to convert it out to a GeoTIFF also crashes QGIS. For some reason I can’t find GRASS in 1.8 … guess something broke there when I installed 1.9.

    • I must admit I haven’t tested my method using the dev build. GRASS should come with QGIS 1.8 in the stand-alone Windows installer. The alternative would be to use SEXTANTE in QGIS 1.8 which should expose the GRASS geoalgorithms that you need.

  2. Running this currently and things are going good. Does the r.turf.contour process usually take awhile (hours) to run? My resolution is a 1 meter contour interval.

    • Hi Chad, it depends very much on the size of the datasets you use, processing power of the machine you are on, etc. However, if you are able to let it sit there and process it should get through it eventually.

      • followed all the steps up until “Select the layer then go to Layer > Properties > Style > Single band properties > Color map and change this to ‘Pseudocolor’ to get a better visual effect”. after clicking apply and ok. i got a white space on the layer. there was nothing on it. i dont know what happened. Im using qgis pisa 2.10

      • Have you selected a colour map and then hit Classify in the top right corner of the dialog box before Apply and OK? If no colour map is chosen then the layer will only render as white. Cheers,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s