Working with elevation data and GDAL

Introduction

With the recent addition of gdaldem (previously available as DEMtools) to the set of GDAL utility programs, there are now several GDAL programs available for working with digital elevation models (DEMs).  Gdaldem adds the abilities to create hillshade, slope, aspect and coloured relief rasters.  To get these programs, you will need to download and compile GDAL SVN trunk or a nightly snapshot, as they are included in the 1.7 development version.

Sample Data

The data used in the following examples are from the Shuttle Radar Topography Mission (SRTM) dataset, version 4.1.  The DEM tile name is srtm_13_04 and the data are in TIFF format.  A subset of the data was extracted to facilitate visualizing the results of the exercise.

Process and Results

The subset was extracted from the source data using gdalwarp.  A rectangular area at the top right of the image with the extents of (-116.1, 43.9) to (-115, 44.99) was extracted with the following command:

gdalwarp -te -116.1 43.9 -115 44.99 srtm_13_04.tif clip.tif

The resulting DEM, when displayed in Quantum GIS with the Contrast Enhancement set to Stretch MinMax:

DEM with stretched contrast

DEM with stretched contrast

Using gdaldem color-relief, one of the new tools in GDAL 1.7, the DEM can be turned into a coloured relief based on a colour ramp.  First, it is necessary to create a text file containing the colour ramp information.  The ramp used in this example is as follows:

100%  255 255 255
75%   235 220 175
50%   190 185 135
25%   240 250 150
0%    50  180  50
nv    0   0   0

The first column contains  the elevation values where specific colours are defined, specified either in elevation units, or as a percentage where 0% is the minimum and 100% is the maximum value in the DEM.  The remaining columns are used to define the colours.  They can either be in RGB triplets or common colours.  See the gdaldem documentation for further explanation.  The command to created the coloured relief was as follows:

gdaldem color-relief clip.tif ramp.txt colored.tif

The output raster appears as follows:

Coloured relief

Coloured relief raster

gdaldem slope creates slope maps that show the steepness of the slopes in the DEM in either degrees or percentage.  The following command creates a slope map in degrees (specifying the -p parameter would use percent slope); the -s 111120 parameter specifies the ratio between ground units (degrees) and vertical units (meters).

gdaldem slope clip slope.tif -s 111120

Dark areas in the image below are where there is little or  no slope; bright areas have steeper slopes.  The maximum slope in this map is about 56 degrees.

Slope map

Slope map

Aspect maps can be created using gdaldem aspect.  The following command will create an aspect map based on the azimuth of the landforms; it is also possible to have the program output the trigonometric angles.

gdaldem aspect clip.tif aspect.tif

The colours in the following map are a colour map applied to the output image.  Blue values are north to north-east, cyan is east, yellow is west, and red is north to north-west).  White areas (actually transparent because they are no data cells) are flat.

Aspect map

Aspect map

The final tool in the gdaldem toolset is gdaldem hillshade which creates hillshaded rasters from an input DEM.  You can specify options such as the vertical exaggeration factor, and the azimuth and altitude of the sun.  In the following command, the vertical exaggeration was set to 5 (-z 5):

gdaldem hillshade clip.tif hillshade.tif -z 5 -s 111120

The image below shows the hillshade on the top half, and a combination of the hillshade and coloured relief on the bottom half (created  by placing the hillshade above the coloured reliev and setting the transparency of the hillshade to approximately 40% in Quantum GIS).

Hillshade/coloured relief combination

Hillshade/coloured relief combination

Featured Technologies

  • Fusion

    A JavaScript web mapping framework for MapServer and MapGuide OS. More

  • JxLib

    A JavaScript UI framework for MooTools. More

  • MapServer

    A powerful CGI mapping engine. More

  • OpenLayers

    A JavaScript API for accessing maps from a variety of sources. More

©2008 DM Solutions Group Inc. | Privacy Statement | Author Login | FamFamFam