Posted on June 25th, 2012

Working In GDAL (WIG) – Calculating Slope

In this new 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 will 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 first edition of WIG, I show our readers how to use GDAL to calculate slope 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 Slope?

In the world of mathematics, slope is defined as the ratio of your rise to your run – meaning the distance you go up or down divided by the distance you go left or right – so that its value can be negative (e.g. if you are going down and walking to the right on a Cartesian grid). In the world of geospatial data, slope is defined as the steepness of a surface or its inclination; and in this world, slope is always positive. Slope can be an important factor in many engineering projects and academic studies; for instance, when determining the path of a pipeline or road as building on a steep hill is more difficult and expensive than building on a flat surface.

Calculating Slope

In order to calculate slope, I employed the GDALDEM functions – you can find out more about them here. Here are the steps I took to complete the slope 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: cd\test
    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 slope in degrees, I used the following command: gdaldem slope DTM.tif slope1.tif
    1. In this command, the words ‘gdaldem slope’ define the utility that GDAL will use for processing the data
    2. ‘DTM.tif’ is the full name of the input (original) DEM file
    3. ‘slope1.tif’ is the name I chose for the output slope raster file
  6. Commands can be added to end of this string to employ additional functionality:
    1. –p : this will express slope in percent
    2. –s scale=value : replace the word value with the proper scaling factor if the horizontal and vertical units of the input DEM are not the same

Visualizing Slope

In order to visualize the results of this slope calculation, I brought both the original DTM and the slope raster file into ArcGIS and zoomed into raster resolution. From there, I took the following steps:

  1. Right click on each layer to bring up the Layer Properties menu and select the Symbology tab
  2. I selected the same red-to-green color ramp for each layer under the Stretched display option; and then selected Invert so that greens colors represented the lowest elevations/slopes while red represented the highest
  3. I set the Statistics option for each layer to ‘From Current Display Extent’ and then applied a Maximum-Minimum stretch from the pull down menu; by doing this, you are creating a color schema that is based on the local maximum and minimum elevations/slopes
  4. Finally, I applied a hillshade with a value of Z=1 to the DTM to make visualizing the data easier

Below is an animation showing you the results of this visualization process in ArcGIS. The elevations in the DTM ranged from 107.655 to 140.179 meters in this narrow snapshot of the entire layer; while slope ranged from 0.004 to 39.732 degrees. As you will see in the animation, steep slopes are limited and seem to cluster where the elevation is the most extreme. This makes sense as in nature the steepest slopes are often at the tops of hills and mountains.


slope_animation

Click the image above to see an animation comparing a DTM and its GDAL calculated slope layer. (DTM Source: DigitalGlobe)

 

Brock Adam McCarty

Map Wizard

(720) 470-7988

Brock@apollomapping.com

Share This Article
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.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

    The Geospatial Times Archive