Posted on August 27th, 2012

Working In GDAL (WIG) – Creating a Hillshade Layer

In this monthly series, I turn my attention to one of the most powerful software packages for raster processing available – the Geospatial Data Abstraction Library (GDAL) – and as an added bonus, it’s free! Each month, I focus on a different utility offered in GDAL, walking the reader through its applications and offering up a series of tips and illustrations so that you can emulate this process in your office and/or home. In this edition of WIG, I show our readers how to use GDAL to create a hillshade layer from a raster digital elevation model (DEM).

About GDAL

GDAL is an open source software application that was launched in 1998 and has been updated multiple times since. While the current version of GDAL (i.e. version 1.9) can be downloaded from multiple locations, I find this site to be the most up-to-date and easy to navigate. I suggest downloading the stable version of the MSVC2010 build for either 32-bit or 64-bit PCs depending on which you have access to. GDAL contains a wide array of utilities to help you process raster files. I find that GDAL is more stable and runs quicker than ArcGIS, ENVI and PCI for data production – although the toolkit is more limited than these applications. GDAL does not rate high for user-friendly functionality as it is command line driven (i.e. words and text, not mouse clicks); and this is the inspiration for creating the WIG series.

What Is a Hillshade Layer?

A hillshade layer is a way to visualize elevation data so that pixel values are based on the illumination intensity they would receive from a hypothetical sun. A hillshade is typically created in 8-bit format so that there a possible range of values from 0 to 255 for each pixel – with 0 representing total darkness and 255 representing complete illumination. To create a hillshade, users must input: (1) the azimuth of the ‘sun,’ or the cardinal direction it is pointing at the ground; and (2) the altitude of the ‘sun,’ or how high it is in the sky. For example, an azimuth value of 90 degrees means that the sun is pointing at the ground from the east, or is much like a morning time sun. And then combined with an altitude of 45 degrees, this would mean that the sun’s rays are coming at the ground from both the east and then from a tilted position in the sky. Azimuth and altitude are combined with calculations of slope and aspect to calculate a hillshade with illumination values that are dependent on the terrain of neighboring pixels. More specifics on the calculation of a hillshade layer can be found here.

Creating a Hillshade Layer

In order to create a hillshade layer, I employed the GDALDEM functions – you can find out more about them here. Here are the steps I took to calculate a hillshade:

  1. I moved my DEM file, a digital terrain model (DTM) produced by DigitalGlobe with 2-meter resolution over Gadara, India, to a folder called, ‘Test,’ located the root of my C: Drive
    1. I chose a simple folder name and file location (i.e. C:test) for the data to make things easier when working with the command line interface of GDAL
  2. I also changed the name of the DTM file to ‘DTM.tif’ to make things easier when working with GDAL
  3. After starting up GDAL, I used the command: cdtest
    1. This command points GDAL to the folder I created with the DTM
  4. If you would like to get a list of the files in the folder you are working in, use this command: dir
  5. To calculate hillshade, I used the following command: gdaldem hillshade DTM.tif hillshade1.tif –z 4 –az 90 –alt 45
    1. In this command, the words ‘gdaldem hillshade’ define the utility that GDAL uses to process the data
    2. ‘DTM.tif’ is the full name of the input (original) DEM file
    3. ‘hillshade1.tif’ is the name I chose for the output hillshade raster file
  6. I also used a series of extra commands added to end of this string to employ additional GDAL functionality:
    1. –z -> this is a multiplier to exaggerate the affects of elevation on the hillshade
    2. –s scale=value : replace the word value with the proper scaling factor if the horizontal and vertib. –zero_for_flat -> replace 0 for default value of -9999 for flat areas, or areas with no aspect
    3. –az -> this is the azimuth of the sun, whereby 0 means the sun’s rays are hitting the DEM from the north, 180 when the sun rays come from the south and so forth
    4. –alt -> this is the altitude of the sun, whereby 0 means the sun is flat to the horizon and 90 means the sun comes from right above the DEM

Visualizing a Hillshade Layer

If you are a regular reader of WIG, you may remember the plethora of issues one can encounter when visualizing aspect, given the continuous nature of this variable and the way that ArcGIS functions. When it comes to a hillshade layer, visualization is a more straight forward process. As such, I focus on the impact of azimuth on hillshades for the remainder of this edition of WIG.

In order to explore the impacts of azimuth, I created four hillshades with GDAL: one with the sun rays coming in from the north (i.e. –az 0), one from the east (i.e. –az 90), one from the south (i.e. –az 180) and one from the west (i.e. –az 270). I then brought each of these hillshades and the source DTM into ArcMAP 10.0. For this article, I colored the DTM with a simple black to white ramp, setting black as the lowest elevation. To do this, I used a process similar to what is put forth in this edition of WIG.

Next, I used the same ArcMAP procedure and black to white color ramp to visualize each of the four hillshades. The black to white color ramp matches the impacts of illumination: with black shades representing surfaces with less illumination (i.e. dark surfaces), and white shades representing those with more illumination (i.e. bright surfaces). As a final step, I moved the hillshades in the Table of Contents so that they overlaid the DTM. Now I set the transparency of each layer to 75% by going to ‘Properties’ (right-click on the layer name) and then ‘Display.’ This step helps to make a more photo realistic view of the terrain. The animation below shows you the four hillshades I created by changing the direction of the sun rays from North to East to South to West.


Click the image above to see an animation comparing the four hillshades I created for this edition of WIG. (DTM Source: DigitalGlobe)

What should be apparent from this animation is the large influence the sun’s position (i.e. its azimuth) has on the illumination of terrain. As I altered the azimuth used in GDAL’s hillshade calculation, the position and direction of the shadows shifted as one would expect to see in the morning (an easterly sun) versus the afternoon (a westerly sun). For those looking to explore this topic in more depth, I encourage you to see how altering altitude and the z- exaggeration factor changes hillshade results.

Brock Adam McCarty

Map Wizard

(720) 470-7988

This entry was posted in The Geospatial Times and tagged , by Apollo Mapping. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.