๐Ÿ†• Visualising a road gradient using a Digital Terrain Model

Introduction

Visualising a road gradient is very useful for a number of reasons and for various road users. It helps drivers, especially drivers of HGVs, to avoid roads that may be too difficult to negotiate in their vehicles; It can help cyclists or hikers choose routes that are appropriate for their fitness levels and avoid those that are too long or too steep; Conversely, tourists may want to find steeper roads as these may offer better viewpoints or are more scenic; and Blue light services can identify flatter routes that mean they can identify a potentially quicker route to an emergency.

What do you need?

In this demonstration we are going to create a visualisation of the gradient for one road.

The data being used is the OSMM Highways Network Roads GML option downloaded from the OS Data Hub.โ€ฏ For the purposes of this exercise a rectangle was drawn to capture all the roads from Stockbridge to Sutton Scotney in Hampshire.

  • The GIS software used is QGIS 3.22.4 โ€“ Biaล‚owieลผa.

  • Two plug-ins have been installed in this version of QGIS for this demonstration: Road Slope Calculator; and Terrain Profile.

  • The Light_27700 map from the OS Maps API is also used as background mapping in QGIS to add some geographic context.

  • The Digital Terrain Model (DTM) data being used is a merged Cloud Optimised GeoTiff (COG) derived from Ordnance Survey Terrain 05 ASCII data, tile numbers used for this demonstration are: SU33NE; SU33NW; SU33SW; SU43NE; SU43NW; and SU44SE (please see Creating a Digital Terrain Model for details)

Although we are using a road from OSMM Highways and a DTM derived from Terrain 05 Ordnance Survey do supply Open Data products, namely OS Open Roads and OS Terrainยฎ 50 which could be used instead.

Method

Start a QGIS session.

Once you have downloaded and unzipped your data package from the OS Data Hub, load the RoadLinks into QGIS (they will be named something like this: Highways_Roads_RoadLink_FULL_001.gml.gz (there is no need to unzip the .gz.))

Select the road that we want to visualise

We are going to look at just the one road, the A30, so we need to find this and export it.

Make sure the roadlinks are selected in the layer window in your QGIS session and click on the 'Select Features using an Expression' button, which has a yellow square and an ฦ on it. This will open a window in which you can build expressions. In this case we are doing something fairly straightforward:

  1. Click in the drop down arrow next to Fields and Values.

  2. Double click on road_classification_number (this will add this attribute to the Expression window)

  3. Type = 'A30' next to "road_classification_number" in the Expression window.

  4. Click Select Features

Save the Road

To save the A30 right click on the roadlinks layer and select Export > Save Selected Features As.. This will open a new window where you can browse to a location and save the road. Save this as a Shapefile (shp) and call it the A30.

Close all the roadlinks so that just the A30 is left. If you draw the map up in QGIS now it will look something like this (road accentuated for clarity).

Create one single line for the road

This line is made up of individual line elements where they have been split at road nodes at junctions for example. It also contains double lines (two carriageways at one point) and roundabouts. Ideally, for this exercise we only want the one line so 'toggle editing' by right clicking on the layer A30 and selecting 'Toggle Editing' (with the yellow pencil symbol).

You will know that you're in editing mode after clicking on Toggle Editing for the A30 layer because the A30 will now have a yellow pencil superimposed over the layer symbol next to the name in the Layer panel

Make sure that Select Features is selected (the button is next to Select Features using an Expression and looks like a yellow square with a white pointer and a larger dotted square)

Now you can start editing the road to reduce it down to one line by left clicking on a link to select it and then hitting Delete to delete it! You can hold down Ctrl while you left click to make more than one selection. Get rid of all the most southerly lines from the road and roundabouts until there is just one line left.

Once you're happy that you have deleted all the lines that you need to right click on the A30 layer, click Save Layer Edits and then toggle editing off.

We now have what looks like a single line but it is still made up of multiple links. We need just one line, not a multiline. We can create a single line by selecting Vector > Geoprocessing Tools > Dissolve. This will open the Dissolve window so select the A30 road. Also select a memorable destination folder and name, for example A30Dissolved.

Click Run. This will then open the log window. You can hit close on this once it has finished.

We now have a single line that we can now calculate gradients for! But at the moment we don't have anything to calculate slope or gradient against so open your DTM layer in the QGIS session.

Calculate the road slope

Move the DTM (called merged_cog.tif for this exercise) down the layer pane so you can see the newly created single line for the A30.

We now need to open the plug in called Road Slope Calculator. This can be opened through the Toolbox in QGIS by selecting Processing > Toolbox.

When the Toolbox window opens start typing 'Road slope calculator' in the search bar (the Toolbox search bar uses type ahead so the search bar will find the plugin before you type all of the name!)

Double click on the Road slope calculator in the Toolbox window to open the plugin GUI. Select merged_cog for the Digital Terrain Model; Select A30Dissolved for the Road network vector layer; and Select a destination and name for the output shapefile.

This process will create a new segmented line (wait, what? We've just created a single solid line!!! Yes, but this new one has equal lengths, read on...) with 2 additional attributes; Length and Slope_% so choose a location and a name for this new output and then click Run. You can close the resultant log window after the process has run.

The new segmented line will automatically draw up in the QGIS session.

If you now open the attribute table, you can see the new columns. We will style the line using the Slope_% attribute.

Style the road

  1. Right click on the new line and select Properties > Symbology.

  2. Use the drop-down-menu next to Value and choose Slope_%.

  3. Click on the line next to Symbol and change the width from 0.26000 to 1 (for clarity).

  4. Select Graduated from the drop-down menu at the top of the window. Choose the RdYlGn colour ramp from the Color (sic) ramp, but invert this so that it starts with green. You will have to expand the list by clicking All Color Ramps, the RdYlGn option is about 3/4 of the way down. Then invert the colour ramp by clicking Invert Color Ramp at the top of the drop down list.

  5. Click on Classify. Leave all other default values and then click OK

Each individual segment of the road will now colour up according to the Slope_% attribute and should now look like this:

Plotting the road profile

This will open the following window at the bottom of the screen in your QGIS session:

Click on the DTM layer in the Layout view (merged_cog in this case) to select it and then click the add Add Layer button, this will load the DTM to the GUI.

Next, using your cursor, left click along the length of the road until you get to the end. You will notice a graph of the profile of the road drawing up as you do this:

The graph will look like the image above, note the minimum and maximum height values of this particular road length. You can also move the cursor within the graph to see the height at a particular point on the road.

The graph can also be saved as a png file by clicking the Save as button and selecting a destination and name for the output. There are also options to save out as a graph in svg, a 3D line in dxf or a 2D profile in dxf.

And there we have it, visualising a road gradient using a Digital Terrain Model.

Last updated