A Guide about extracting Contours from a DEM using QuantumGIS
For those who don’t want to spend bucks for ESRI’s Spatial Analyst extension there is an absolutely free (and open source) solution to export contour lines from a Digital Elevation Model (DEM). We will show you how to do it using QuantumGIS (also known as QGIS), a free Desktop GIS. QuantumGIS uses GDAL to handle raster datasets. GDAL is a translator library for raster geospatial data formats that is released under an X/MIT style Open Source license by the Open Source Geospatial Foundation. As a library, it presents a single abstract data model to the calling application for all supported formats. It also comes with a variety of useful commandline utilities for data translation and processing., and GDAL can load almost every format out there.
Getting Software and Data
First of all you need to obtain a Digital Elevation Model, a “piece” of raster data from which you will export contour lines in a shapefile. We suggest you to try downloading ASTER DEM data as we will use this type of data in our example below. If you need assistance about downloading ASTER DEM data visit our article: How-To download ASTER v2 Global Digital Elevation Model. In our example we will use QuantumGIS 2.2 release so if you also want to use it download from the official QGIS website.
Once you installed QGIS and run it you will see the environment below:
Then, from the main menu (see image below) above choose “Layer” and click “Add Raster Layer…”. Choose the dem raster file (the .tif one) and click “Open”.
The next screenshot show what you must see if the DEM raster file opened correctly…
Next step is to run the needed GDAL commands to extract the contour lines. QGIS has a bult-in GUI to run these commands. So, at the main menu choose “Raster”, then “Extraction → Contour”.
Now, you see the popup window below. Let’s explain the fields which is needed to be filled…
Input file (raster): You will see here the DEM raster file you added in QGIS before, otherwise click “Select…” and add it again.
Output file for contour lines (vector): Click “Select…” and type a file name to save the vector file with the contours. NOTE: Look at “Files of type” to be ESRI Shapefiles (*.shp)
Interval between contour lines: Choose the value of the interval between contours. e.g. 10
Attribute name: Choose Attribute name (and also type the name of the field) if you want to add elevation data in vector file’s attributes.
Load into canvas when finished: Choose it if you want to add the new vector file in Quantum GIS.
Finally, you can see in the text box the complete GDAL command which will be used to export the contour lines from the DEM… So, click… “OK” …and wait…..
Once the process will finish click “Close” and then, you will see the vector file which added in the Layers box and of course the contour lines in front of the DEM file (see images below).