Posted on July 18th, 2012

Working In GDAL (WIG) – Calculating Aspect

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 my work in your office and/or home. In this edition of WIG, I show our readers how to use GDAL to calculate aspect 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 Aspect?

When describing terrain, there are three crucial elements one needs to consider: (1) the elevation, which is provided as a raster DEM in this case study; (2) the surface’s slope or its steepness (we discussed the concept of slope in detail in last month’s WIG); and (3) its aspect or orientation. Aspect is the direction of the steepest downhill slope. It is reported as degrees (or radians) from the established zero marker (usually North) and is also called the azimuth angle. Aspect is an important consideration as it determines: the direction water will flow down a slope; what is visible from a given location; and the amount of sun and wind a site receives. Areas with no slope (i.e. that are completely flat) also have no aspect.

Calculating Aspect

To calculate aspect, I employed the GDALDEM functions – you can find out more about them here. These are the steps I took to complete the aspect calculation:

  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 aspect in degrees, I used the following command: gdaldem aspect DTM.tif aspect1.tif
    1. In this command, the words ‘gdaldem aspect’ define the utility that GDAL will use for processing the data/li>
    2. ‘DTM.tif’ is the full name of the input (original) DEM file
    3. ‘aspect1.tif’ is the name I chose for the output raster file
  6. Commands can be added to end of this string to employ additional functionality:
    1. –trigonometric -> this will express aspect in radians
    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

Visualizing Aspect

Calculating aspect can an easier task than visualizing the results as aspect is a continuous variable, making it difficult to display with a color ramp. Consider a map of aspect with 360 shades of blue or 360 shades of colors from red to blue representing each degree of the compass rose; and now consider the challenge of determining slopes that face ‘north’ from those that face ‘east.’ Another challenge of visualizing aspect is that north, south, east and west are relative terms and so the range of degrees that each represents depends on the needs of the project. As such, for the rest of this WIG, I walk you through the steps I find best for visualizing aspect. I start with displaying aspect as a continuous color ramp and then conclude with the steps to classify it according to north, south, east and west.

To create an aspect map with a continuous color ramp, follow these steps in ArcMap 10.x:

  1. Right-click on the aspect layer and select Layer Properties.
  2. Now select the Symbology tab and then the Stretched option. It will ask you to built histograms, I said ‘Yes’ when asked to do so.
  3. Now set the Custom Settings for statistics (at the bottom of the window) to 0 to 360 as that is the range of values we focus on here. To have a truly flat area would be rare (i.e. a value of -9999) so I have not included instructions on how to handle flat areas in this WIG.
  4. Finally, select a color ramp. For this WIG, I use a light red to dark red color ramp.

The results of this continuous color ramp are shown as the first slide in the animation below. Next, let’s create a map with 4 color classes, one each for north, south, east and west, as this will create an easy to interpret map of the general direction a slope faces. For some applications, you may require greater fidelity, such as classes for north-east, south-west, etc., and the basic steps put forth in this WIG will help you through such a classification if that is your end goal. In order to create a 4-class aspect map in ArcMap, you can follow these steps:

  1. Return to the Symbology tab for the aspect layer and now select the Classified option.
  2. Push the Classify button and select Defined Interval from the drop down menu.
  3. 3. Select the Interval Size you would like, I used 90 in this case study to divide the compass rose into four even classes. Also, set the Exclusion values so that ArcMap only recognizes the range of [0, 360].
  4. 4. Now select the color ramp you like, I used the same light red to dark red ramp as in the aspect layer with continuous symbology. Choosing a light to dark color ramp makes it easier to interpret the four colors for each class, as north facing slopes would be the lightest and then west would be the darkest.

The results of this 4-class symbology are shown as the second image in the animation below. While it seems like we have reached the end of this case study on visualizing aspect, we are in fact a few important steps away. Let’s examine the results of the 4-class aspect map I created above. When I created the classes, ArcMap automatically assumes that 0 degrees is the starting point and then adds 90 3 times to create the final classes, so that:

North = 0 to 90 degrees

East = 90 to 180 degrees

South = 180 to 270 degrees

West = 270 to 360 degrees

But that is not correct, as you might realize, in that North in a 4 class system is generally thought of 315 to 45 degrees and so forth. ArcMap cannot handle making this modification in a clean fashion as it looks at 0 as the starting point for numeric calculations. To work around this, you can follow these steps:

  1. Open the Symbology tab for the aspect layer and select the Classified option again (if you are not already there).
  2. Set the number of Classes to 5, press the Classify button and then select Manual from the pull down menu.
  3. Now type in these 5 break values: 45, 135, 225, 315 and 360.
  4. Select the color ramp you like, I chose the same light to dark red ramp.
  5. The final step involves grouping the first and last class together as these cut across the 0/360 divider line for degrees on a compass rose. You can do this by holding down the Control Key and left-clicking on each class. Now right-click and go to Properties for Selected Colors; press More Colors and then Okay. This will make the first and last class the same colors.

What you have done now is create 4 color classes that represent these more intuitive compass rose ranges:

North = 315 to 45 degrees

East = 45 to 135 degrees

South = 135 to 225 degrees

West = 225 to 315 degrees

The results of this corrected 4-class aspect map are shown as the third and final image in the animation below. When you watch the short animation, you will see how important this correction is for understanding the direction a hill slopes, or its aspect.


color_ramp
GDAL is free and can calculate aspect from raster elevation data.

 

Brock Adam McCarty

Map Wizard

(720) 470-7988

Brock@apollomapping.com

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.