Video - Introduction to Raster Data (Part 2): Digital Elevation Models (DEM) Tools and the Raster Calculator

Catalogue number: Catalogue number: 89200005

Issue number: 2020020

Release date: December 1, 2020

QGIS Demo 20

Introduction to Raster Data (Part 2): Digital Elevation Models (DEM) Tools and the Raster Calculator - Video transcript

(The Statistics Canada symbol and Canada wordmark appear on screen with the title: "Introduction to Raster Data (Part 2): Digital Elevation Models (DEM) Tools and the Raster Calculator")

So welcome back everyone. For Part 2 of Intro to Raster Data we'll explore some DEM specific tools, particularly the Slope, Hillshade and Aspect tools. For each of these, there are multiple alternatives available in the Processing Toolbox, each with slightly different parameters and applications. Then we'll move on to the raster calculator, first using it to select cells by criteria of interest, and then to combine raster variables for further analysis. Broadly, DEMs and related datasets can be used to extract 3D information and conduct a wide-variety of analyses and visualizations. This is because elevation and its related characteristics significantly influence both biophysical and socio-economic processes. Just a few examples include daylight hours, growing season lengths, soil erosion potential, visibility and optimal routes for transportation or movement across a landscape.

So with the pseudocolour DEM loaded and duplicated in the Layers Panel, the first tool we'll explore is the Slope tool. As alluded to, there are many options. We'll use the GDAL Slope tool. The ratio of vertical to horizontal units is 1 to 1, since we transformed the merged DEM to a projected coordinate system, with units in metres in the previous demo. Otherwise we'd have to calculate and enter the appropriate ratio of 1 metre to 1 degree. Optionally, we can calculate slope as a percentage instead of degrees, which would be suitable for flatter locations. However, with rise over run slope at 45° is 100%, and as it approaches 90 degrees approaches infinity. And therefore we'll leave it unchecked to avoid astronomically large and unintuitive values in the output, given the mountainous terrain. We will check Compute Edges to avoid potential adverse edge effects and then run with a temporary file. So I've used the Build Pyramids tool on most rasters in this demo to improve rendering times, which you can do as well.

So as we can see Slope varied between 0 to 80 degrees. And unsurprisingly there are many more changes in slope in the mountainous southwest area of the DEM compared to the flatter region in the northeast. Slope is a key parameter in many analyses, such as determining the optimal route across a landscape or examining risk potential for mass movements like land-slides or avalanches.

The next tool that we'll examine is the Hillshade tool, once again using the GDAL version. If we were in a flatter location, such as the Prairies, we could apply a vertical exaggeration factor such as 5 or 10. And this effectively acts as a multiplier to enhance the visualization of elevation changes. For our area the default of 1, meaning no exaggeration, is appropriate. Leaving the next three parameters as default, we can check Compute Edges and run the tool once with Combined Shading and then again with Multidirectional Shading checked.

But as noted in the previous demo, we can also apply Hillshade as a visualization style to our DEM in the Rendering drop-down of the Symbology tab. And this is the traditional single-light source hillshade. So let's click Apply – and then I'll adjust the canvas scale to better see the visualization.

So the azimuth defines the horizontal direction of sunlight, from north, south, east or west, in degrees. So the default of 315, means that lighting is coming from the northwest, with shading occurring on the southeast facing slopes. We can alter the values in the box and click Apply. So lighting from the East adjusts shaded areas to the western facing slopes. Alternatively, we can also spin the Azimuth wheel. With lighting from the south, logically, the shade occurs on the north facing slopes. I've included links to the guides for determining realistic azimuth and angle values for a given location and at a time of interest in the video description. So the Altitude parameter adjusts the vertical angle of the sun in the sky. Altering the value to 25, shadow lengths shrink, because as it approaches 0° lighting is occurring from directly overhead. Then changing to a value of 75, the length of shadows increases substantially. As the angle approaches 90° lighting is occurring from the horizon, like with sunrise or sunsets. Now we'll switch back to the default settings by clicking on the tabs, and click OK.

Now let's take a look at the multi-directional and combined hillshades. So as we can see the multidirectional hillshade is relatively similar to the traditional hillshade, with just a few additional lighting sources incorporated in the output. Conversely, the combined hillshade is notably different from the others, since lighting is occurring from all directions. In the Transparency tab set the global opacity to 50%. Now let's toggle on the duplicated DEM and drape the hillshade over it. This is another standard visualization of DEMs. It provides a pseudo-3D visualization, with the texture of the mountainous terrain draped over the pseudocolour visualization of elevational changes. And we could use any of the output hillshades for this purpose. To create an actual 3D visualization of the overlaid rasters, expand the View drop-down and select New 3D Map View. Click the Configure icon and specify the DEM raster in the drop-down. Clicking OK, back in the 3D Map View window we can hold the Ctrl key and left-click to change the tilt of the 3D view. Then we can use the scroll-bar on the mouse to zoom in or out.

Hillshades also have multiple analytical applications, since they are another key factor influencing properties such as melt periods, growing conditions and vegetation distribution. And this influence also extends to our next tool, the Aspect tool.

The Aspect tool creates a raster showing the direction of hillslopes expressed in degrees. Once again we'll use the GDAL tool. Check return 0 instead of -9999 for flat areas and Compute Edges, selecting the DEM as the input, and then run with a temporary output file. The output then appears as such. For a more intuitive visualization switch the Render type to Singleband Pseudocolour with a Spectral colour ramp and click Apply. This should distinctively colour the four cardinal directions, and we can substitute values in the Label column for their text equivalents: entering E for east for 90 degrees, S for 180 degrees, W for 270 and N for 360, as well as flat areas for 0. If we change the mode to Equal Interval and then the classes to 9 we can also add inter-cardinal directions and relabel as needed. So 45 would be northeast, 135 would be southeast, and so on.

So now we'll move on to the Raster Calculator. It is akin to the Select by Expression, Field Calculator and Intersection tools for vector data combined. It is a versatile tool that can be used to query, reclassify and combine raster files. We'll explore some of these applications with a simple scenario. So say we want to isolate the locations for a new farm with some known environmental constraints corresponding to our existing rasters. We can use the Raster Calculator to isolate those areas. So let's begin by selecting cells by criteria of interest. We'll use the Slope raster, specifying cells with a slope less than or equal to 10 degrees.

"Slope@1" <= 10

And here, the @1 symbol refers to the band number, relevant for composite rasters. So for single-band and thematic rasters there is only one band, meaning all of them will be followed by @1. The only other required parameter is a reference layer, here using the Slope raster. Then we can run the tool with a temporary output.

When it completes, the output appears like this. So open the Layer Properties box and change the render type to Paletted - clicking Classify. As we can see– the values are 0 or 1, indicating False and True for the specified criteria. So re-enabling the duplicate DEM, unsurprisingly the zero values mostly occur in the mountainous area, while ones correspond to select valley bottoms and flatter areas in the northeast.

So reopen the calculator. To retain the input values that match our criteria of interest we must multiply our original query by the input raster. This is because cells that match the criteria will be multiplied 1 by the original value, which equals the original value. Conversely those that do not meet the criteria will be 0 multiplied by the original values, which will always be 0 – retaining only the cells that match that particular criteria. Once again provide the reference layer and then run.

("Slope@1" <= 10)* "Slope@1"

Now we could repeat with a slightly more complex example, using the Aspect raster to isolate east, south and west facing slopes. Start with a double-open bracket, then enter aspect greater than or equal to 90 AND less than or equal to 270 degrees – which will exclude our north facing slopes. However, if we also wanted to include flat areas we could add OR equal to 0 as a separate component using our Expression syntax. Then close the brackets and multiply by the Aspect raster to retain their specific values. Copy this expression for reuse in the next example. If any issues were encountered using the Raster Calculator, the r.reclass tool could be used to retain and reformat values of interest within a raster – and we'll cover this tool in an upcoming demo.

(The words: "(("Aspect@1" >= 90 AND "Aspect@1" <= 270) OR ("Aspect@1" = 0))* "Aspect@1"" appear on screen.)

Now let's use the Raster Calculator to combine variables of interest. Here we'll combine the previous queries to create a weighted raster in assessing the suitability of locations for a new farm according to the specific conditions of interest. So start with adding open brackets and slope less than or equal to 10 degrees.

Close the bracket and then multiply the expression by 0.75 to assign the weighting value and close the bracket.

(The words: "(("Slope@1" <= 10 )*0.75)" appear on screen.)

Provided the weighting values add up to 1, we can combine as many raster layers as are relevant to the analysis. Here we're assigning a greater weight to slope conditions. Now add plus, open bracket and paste in the Aspect query from the previous example. Multiply the query by 0.25 and close the bracket.

(The words: " + ((("Aspect@1" >= 90 AND "Aspect@1" <= 270) OR ("Aspect@1" = 0))*0.25)" appear on screen.)

Now we can run the tool and create our weighted raster of the slope and aspect variables.

The values of the output are between 0 and 1, but unlike the binary true-false raster we initially created, this raster contains a gradient or range of values. Switch the Render type to pseudocolour and apply a Greens colour ramp. So values closer to 0 are less suitable according to the specific conditions, while areas closer to 1 are more suitable. As we established, the most suitable locations correspond with the flatter northeast region, while the mountainous areas are largely unsuitable. We could incorporate other rasters for a more realistic assessment, such as masking out any lakes, rivers or existing for farmland, or incorporating soils layers, in isolating suitable sites for a new farm.

We can then also use the Contour Tool (GDAL) in the Processing Toolbox to create isolines from the raster datasets. Isolines delineate areas of equal value, with contours specifically referring to elevation. Using the DEM as an input, we can switch the Attribute Name to Z - a common abbreviation. And change the Interval to 250 or 500 to reduce processing time and the file size. We could Check 3D vector to enable 3D visualizations of our output. Finally we'll enter a NoData value of -9999 – and run the tool. Although applied to the DEM here, it could be applied to any single-band raster, including slope, aspect or as another example using agricultural soil samples we could create a raster and contours showing areas of equal fertilizer, pesticide or nutrient application. We'll use this tool again in an upcoming demo.

We can overlay the output contours over the DEM and adjust visualization, such as adding labels as required.

And to conclude I'd just like to highlight some additional analysis that can be done with the available tools to demonstrate the finer resolution analyses that can be performed using raster datasets. So the first is a cost direction and cumulative cost raster, generated using the DEM, Slope and Annual Crop Inventory rasters for the region, with defined Start and End Points. The Slope and Annual Crop Inventories were reclassified and combined to create a Friction raster, dictating the costs associated with travelling between cells. So Urban, Agricultural and Forest classes and areas of lower slope values assigned smaller costs than other covering other land-cover classes and higher slope areas. Switching to the Cumulative Cost raster, once again we can see that the costs of traversing the mountainous area were much greater than the foothills and plains to the northeast.

The second example is a Viewshed from one of the mountain tops, showing the areas that were visible from a selected point. Viewsheds are used in landscape planning and architectural applications to ensure viewlines are retained and safety requirements are adhered to. So the tutorial and additional examples demonstrate how we can derive diverse analytical products from just a few simple layers – ranging from routing optimization to planning applications to environmental analysis.

(The words: "For comments or questions about this video, GIS tools or other Statistics Canada products or services, please contact us:" appear on screen.)

(Canada wordmark appears.)

Date modified: