I am working on a project for a machine learning class wherein I extract features from a topographic raster map and then classify the traversability of the terrain. One of the features I need to extract is slope. My initial thought was that an approximation of slope at any given point could be extracted from a map by calculating the distance between contour lines. However it seems I took for granted the complexity of extracting the contour lines.

In attempting to solve this problem I found myself trying to learn a number of GIS tools. However I still have not been successful which is why I am here. I have installed gdal and used gdal_contour to generate what I believe to be a DEM. From there I loaded it into qgis along with the original raster map. From this I see that when gdal created the DEM it used only one of the two colors that designate contour lines. Worse yet it used the less frequent color so the resulting contour lines are highly segmented.

This leaves me with a couple of questions. The first is whether it is possible to designate the colors gdal uses to extract contour lines and generate the DEM. The second is whether there is a simpler method for extracting the desired data.

  • 1
    If I understand you correctly, I think you'll struggle to extract the elevation data you need from the contours on a scanned map. Could you not download a DEM from somewhere? From your profile I see that you are in Utah. If your project is local there is what looks like good elevation data available from gis.utah.gov/data/elevation-terrain-data including two metre Lidar. N.
    – nhopton
    Commented Nov 24, 2012 at 12:12
  • That is a great question. That link looks very promising however when I attempt to download the data it gives me a .exe. Do you know why and/or how I am to use that data programmatically? Commented Nov 24, 2012 at 16:00
  • Just a quick update, I see that the LiDAR data is available in ASCII format. Commented Nov 24, 2012 at 16:42
  • 2
    The .exe files appear to be self-extracting archives. If you don't trust running them, you can extract the contents with 7-zip and probably other archive readers. The .exe file I downloaded as a test contains a single compressed .dem file.
    – Llaves
    Commented Nov 24, 2012 at 16:50
  • I want to accept one of the answers below however I could not have solved my problem without a bit from each. From Bernie's post I needed the second part of the tutorial he linked. From markusN I needed to know about the r.surf.contour and r.slope.aspect commands in Grass. From nhopton I needed the fact that there are DEMs available for download. If someone wants to incorporate all of these things into their answer then I could accept it as the most complete answer. Thanks again for the help everyone. Commented Dec 5, 2012 at 17:55

3 Answers 3


You can use the GRASS GIS backend's r.surf.contour to generate a DEM from rasterized contours. Use it through the GRASS toolbox or the Sextante plugin (or directly of course). Subsequently r.slope.aspect will calculate the slope from this generated DEM.

  • I have attempted to import my raster map into Grass but it rejects it saying the data doesn't appear to be in my location. This is an error I don't understand. I also tried using the Grass plugin in QGIS but in that case it doesn't let me select my data. Can you elaborate on the process? Commented Nov 24, 2012 at 16:48
  • Personally I think that the GRASS GIS support in the QGIS-Sextante plugin is much easier to use than the toolbox. Then it just takes the data from the QGIS canvas and internally manages data exchange with GRASS.
    – markusN
    Commented Nov 25, 2012 at 10:05
  • I'm confused. Is the QGIS-Sextante plug-in different from the GRASS plug-in for QGIS? And what do you mean by "the toolbox?" Thanks. Commented Nov 25, 2012 at 18:21
  • 2
    There are a) the QGIS-GRASS-toolbox (grasswiki.osgeo.org/wiki/QGIS_GRASS_Cookbook) and the QGIS-Sextante-plugin with GRASS GIS support (grasswiki.osgeo.org/wiki/…). The latter is having a much more intuitive data management.
    – markusN
    Commented Nov 26, 2012 at 11:24
  • I have applied the r.surf.contour but the DEM it creates is nothing like it should be. In fact it appears to just be noise. I assume I'm supposed to supply my topo-map to it, is that correct? Commented Nov 27, 2012 at 2:29

Look at part 2 of this tutorial:


for how to create a GRASS region. The file hierarchy is very fussy - this is the tutorial that helped me to get it right after many frustrating hours of trying!

To download 30m DEMs, go to: http://gdem.ersdac.jspacesystems.or.jp/search.jsp

  • This was very helpful. I have been able to load my raster and use r.surf.contour. Thanks. Commented Nov 25, 2012 at 19:39
  • 1
    Pleasure! Glad it helped :)
    – Bernie
    Commented Nov 26, 2012 at 5:06

If you manage to download a DEM for your area of interest from the Utah site, as a first step I think it would make sense to use this to create a shaded relief image, so that you can make a quick visual assessment of the terrain that you're dealing with.

For example, as an exercise I downloaded a 2-metre DEM (Heber 2m DEM from LiDAR - North) as a zip file that extracted to a number of *.asc files. I made a virtual raster of these (Raster -> Miscellaneous -> Build Virtual Raster) and then loaded the resulting VRT file.

Next, I created a hillshade image from the VRT layer: Raster -> Analysis -> DEM Terrain models. Set "Mode" to "Hillshade", set a "Z factor" of 2, set "Azimuth of light" to 345, set "Altitude of light" to 55. The CRS of this data set appears to be EPSG:26912, this will need to be set in QGIS.

The image below shows a tiny part of the hillshade image. The rectangular features are about 3 km west of Huber and are, I guess, reservoirs or someting similar. Using the raster value tool on the DEM indicates that the outer bund walls are about six metres in height.

After you've had a look at the terrain, you could for example then move on to creating a slope raster from the VRT DEM and rendering this in colours to indicate slope, or ruggedness or what ever you wish.

I'm not quite sure about what your object is. Are you trying to calculate the optimum path from Point A to Point B for an ATV, for example?


enter image description here

  • Hi Nick and thank you for the help. I have been able to download a DEM for my area of interest. As I allude to in my other question I'm not sure how to correlate it with my original raster however. Any thoughts to that end would be appreciated. Also, can you elaborate on how I make a slope raster? I can process the data myself but I assume QGIS also has a tool to do it. To answer your question, my main interest is in path planning for a UGV traveling off-road. Commented Nov 25, 2012 at 18:18
  • 2
    Making the slope raster is simple. Go Raster -> Analysis -> DEM Terrain models and set "Mode" to "Slope". Regarding the question of how you tie the DEM to the map image and vice-versa I'll have a look at the new thread. N.
    – nhopton
    Commented Nov 25, 2012 at 19:59
  • Are your instructions here for QGIS? I don't see a Raster menu unless I open the GRASS tools in which case I don't see a Misc. nor an Analysis sub-menu. Commented Nov 25, 2012 at 20:29
  • Okay, it appears that importing my raster and DEM data into QGIS it automatically correlated the data and it looks great! Thanks again! Commented Nov 25, 2012 at 20:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.