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).
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.
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:
- 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
- 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
- I also changed the name of the DTM file to ‘DTM.tif’ to make things easier when working with GDAL
- After starting up GDAL, I used the command: cdtest
- This command points GDAL to the folder I created with the DTM
- If you would like to get a list of the files in the folder you are working in, use this command: dir
- To calculate slope in degrees, I used the following command: gdaldem slope DTM.tif slope1.tif
- In this command, the words ‘gdaldem slope’ define the utility that GDAL will use for processing the data
- ‘DTM.tif’ is the full name of the input (original) DEM file
- ‘slope1.tif’ is the name I chose for the output slope raster file
- Commands can be added to end of this string to employ additional functionality:
- –p : this will express slope in percent
- –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
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:
- Right click on each layer to bring up the Layer Properties menu and select the Symbology tab
- 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
- 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
- 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.
Brock Adam McCarty