Saturday 30 June 2012

Creating color relief and slope shading with gdaldem

In my previous blog post we created a grayscale shaded relief (hillshade) from a Digital Elevation Model (DEM). Today, we’ll use the DEM to create color relief and slope shading maps.

Color relief or hypsometric tints depict elevation as bands of color, to enhance elevation zones so map readers can better see differences in relief. The colors selected for the tints are assumed to relate to the ground cover typically found at various elevations in the area being mapped. A typical color scheme progresses from dark greens for lower elevations up through yellows/browns, and on to grays and white at the highest elevations. I selected this scheme for my area:

Elevation Color

To create a color relief with gdaldem, we first have to create a text-based color configuration file (color_relief.txt), containing the association between elevation values and colors. The file generally contains 4 columns per line: the elevation value and the corresponding red, green, blue value between 0 and 255 (RGB):

0 110 220 110
900 240 250 160
1300 230 220 170
1900 220 220 220
2500 250 250 250

The above numbers define a gradient that will blend 5 colors over 2500 meters of elevation. We use this command to apply this color ramp to the Jotunheimen DEM:

gdaldem color-relief jotunheimen.tif color_relief.txt jotunheimen_colour_relief.tif

[ Download image ]

A Digital Elevation Model (DEM) can also be used to measure slope, the steepness of the terrain. Slope is estimated by comparing each pixel of the DEM to the elevations of the surrounding pixels. Creating slope shading with gdaldem is a two step process.

First, we use the DEM to create a raster where each pixel contains an angle, varying from 0 to 90 degrees as the terrain ranges from horizontal to vertical:

gdaldem slope jotunheimen.tif jontunheimen_slope.tif

We then use this raster to create slope shading by assigning a color to each pixel, using the same technique as for color relief.

Create a color configuration file (color_slope.txt) containing these two lines:

0 255 255 255
90 0 0 0

Flat terrain will be displayed in white (slope of 0°) and cliffs in black (slope of 90°), with angles in-between being various shades of grey. The command is:

gdaldem color-relief jotunheimen_slope.tif color_slope.txt jotunheimen_slopeshade.tif

[ Download image ]

In the next blog post we’ll combine slopeshade, hillshade and color relief into a single map image.

No comments: