Use QGIS to generate contour lines from a DEM

This guide will help those who have used ESRI software in the past to create countour line datasets.  Instead of spending big bucks on ArcDesktop and the Spatial Analyst you can do this for free with QGIS.

The first step is to load your DEM data.  QGIS uses GDAL to handle raster datasets, and GDAL can load almost every format out there.  Seriously, GDAL is awesome.  Once you have loaded your data make sure it is in the correct projection by right clicking the layer in the table of contents, the select Set Layer CRS.  You’ll also want to set the project to your layer’s CRS, you can either use the Set Project to Layer CRS in the same menu, or go to File, Project Properties, and click the Coordinate Reference System tab.

In other GIS software your DEM may automatically be drawn with a grayscale or colormap already set.  In QGIS by default you’ll only see a gray rectangle.

DEM Loaded

QGIS displaying a DEM with no colormap or grayscale stretching.

On the style tab of the layer properties menu you can select how you want your raster to be symbolized.  Here’s the same layer displayed with elevations represented by pseudocolors:

QGIS pseudocolors

DEM displayed with pseudocolors

To generate contours click Raster, then Extraction, then select the Contour menu.

QGIS Contour menu

QGIS contour menu.

The menu is pretty self explanatory.  It is a front end for the gdal_contour command line tool.  You can use the generated command at the bottom as the starting point for a batch file if you have several files you need to convert.

DEM with contours

Contour lines sitting on DEM they were created from

Easy peasy!

    • Ian Jones
    • June 2nd, 2013

    Awesome, Thanks!

    • Antimo Battistoni
    • April 8th, 2015

    Perfect. Only a little update, QGIS 2.8 can display directly the colours of DEM and the Extraction runs well and fast also with gray scale DEM if you have anyone.

  1. Great tip. I was delighted to find out it created a shp file. How can I add the elevation of the contour into the field value? I want to be able to bring the 3D contours into another program. Thanks.

    • Check the Attribute Name box. By default the field will be named “ELEV” but you can change it if you like.

  1. No trackbacks yet.

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: