LogoLogo
OS Docs HomeOS NGDOS APIsOS Download ProductsMore than MapsContact Us
  • More than Maps
  • Geographic Data Visualisation
    • Guide to cartography
      • Introduction to cartography
      • Types of maps
      • Symbology
      • Colour
      • Text on maps
      • Generalisation
      • Coordinate reference systems
      • Projections
      • Scale
      • Map legends
      • Map layout
      • Relief representation
      • North arrows
    • Guide to data visualisation
      • Introduction to data visualisation
      • GeoDataViz design principles
      • Types of visualisation
      • Thematic mapping techniques
      • Data visualisation critique
      • Accessible data visualisation
      • Ethical data visualisation
      • Software
      • Data
    • GeoDataViz assets
      • GeoDataViz basemaps
      • Stylesheets
      • GeoDataViz virtual gallery
      • Equal area cartograms
      • How did I make that?
        • Apollo 11 Landing
        • North York Moors National Park, 70 years
        • Snowdonia National Park, 70 years
        • Great Britain's National Parks
        • Great Britain's Islands
        • Great Britain's AONB's and National Scenic Areas
        • Famous shipwrecks of Pembrokeshire
        • Trig pillars today
        • Britain's most complex motorway junctions
      • #30DayMapChallenge
  • Data in Action
    • Examples
  • Demonstrators
    • 🆕Product Viewer
    • Addressing & location demonstrators
      • Address Portfolio overview
      • Which address product should you use?
      • AddressBase
      • AddressBase Core
      • AddressBase Plus
      • AddressBase Premium
      • Address Classifications
      • Addressing Lifecycle
      • OS Emergency Services Gazetteer
      • What are Vertical Streets?
      • Why are there differences in boundaries?
    • Contextual demonstrators
    • Customer best practice
      • Channel Shift
      • Data Management and OS Data Hub
      • End User Licence vs Contractor Licence
      • 🆕 IDs vs Spatial Relationships
      • Why we should capture good quality addresses at source
      • Why we Snap and Trace
    • Network Demonstrators
      • OS Detailed Path Network
      • OS Multi Modal Routing Network
        • OS Multi Modal Routing Network
      • Water Networks overview
      • OS MasterMap Highways Network and OS NGD Speeds
      • OS MasterMap® Highways Network and OS Open Roads™
    • OS MasterMap Generation APIs
      • Using the OS Features API
      • Using the OS Features API Archive
      • Using the OS Downloads API
      • Using OS APIs in ESRI Software
    • 🆕OS NGD (National Geographic Database)
      • OS NGD Address
      • OS NGD Boundaries
      • 🆕OS NGD Buildings
        • 🆕Building and Building Access Feature Types
        • Building Part and Building Line Feature Types
      • 🆕OS NGD Geographical Names
      • OS NGD Land
      • OS NGD Land Cover enhancements
      • 🆕OS NGD Land Use
      • OS NGD Land Use enhancements
      • 🆕OS NGD Structures
        • 🆕OS NGD Structures
        • Field Boundaries
      • 🆕OS NGD Transport Features
      • 🆕OS NGD Transport Network
      • OS NGD Transport RAMI
      • OS NGD Water Features
      • OS NGD Water Network
      • OS NGD API - Features
      • Ordering OS NGD data
      • Change only updates
      • OS NGD Versioning
      • Creating a topographic map from OS NGD Data
      • Analytical styling for OS NGD data
    • OS MasterMap® demonstrators
    • 🆕Product & API Comparisons
      • 🆕Comparison of Water Network Products
  • Tutorials
    • GeoDataViz
      • Thematic Mapping Techniques
      • Downloading and using data from the OS Data Hub
      • How to download and use OS stylesheets
      • How to use the OS Maps API
      • Creating a bespoke style in Maputnik
    • GIS
      • Analysing pavement widths
      • Basic routing with OS Open Data and QGIS
      • Walktime analysis using OS Multi-modal Routing Network and QGIS
      • Creating 3D Symbols for GIS Applications
      • Constructing a Single Line Address using a Geographic Address
      • Creating a Digital Terrain Model (DTM)
      • Visualising a road gradient using a Digital Terrain Model
      • Visualising a road gradient using OSMM Highways
    • 🆕APIs
      • 🆕Using OS APIs with EPC API
      • 🆕OS APIs and ArcGIS
  • Deep Dive
    • Introduction to address matching
    • Guide to routing for the Public Sector
      • Part 1: Guide to routing
      • Part 2: Routing software and data options
      • Part 3: Building a routable network
    • Unlocking the Power of Geospatial Data
    • Using Blender for Geospatial Projects
    • A Guide to Coordinate Systems in Great Britain
      • Myths about coordinate systems
      • The shape of the Earth
      • What is position?
        • Types of coordinates
        • We need a datum
        • Position summary
      • Modern GNSS coordinate systems
        • Realising WGS84 with a TRF
        • The WGS84 broadcast TRF
        • The International Terrestrial Reference Frame (ITRF)
        • The International GNSS Service (IGS)
        • European Terrestrial Reference System 1989 (ETRS89)
      • Ordnance Survey coordinate systems
        • ETRS89 realised through OS Net
        • National Grid and the OSGB36 TRF
        • Ordnance Datum Newlyn
        • The future of British mapping coordinate systems
        • The future of British mapping coordinate systems
      • From one coordinate system to another: geodetic transformations
        • What is a geodetic transformation?
        • Helmert datum transformations
        • National Grid Transformation OSTN15 (ETRS89–OSGB36)
        • National Geoid Model OSGM15 (ETRS89-Orthometric height)
        • ETRS89 to and from ITRS
        • Approximate WGS84 to OSGB36/ODN transformation
        • Transformation between OS Net v2001 and v2009 realisations
      • Transverse Mercator map projections
        • The National Grid reference convention
      • Datum, ellipsoid and projection information
      • Converting between 3D Cartesian and ellipsoidal latitude, longitude and height coordinates
      • Converting between grid eastings and northings and ellipsoidal latitude and longitude
      • Helmert transformation worked example
      • Further information
  • Code
    • Ordnance Survey APIs
    • Mapping
    • Routing with pgRouting
      • Getting started with OS MasterMap Highways and pgRouting
      • Getting started with OS MasterMap Highways Network - Paths and pgRouting
      • Getting started with OS NGD Transport Theme and pgRouting
      • Getting started with OS NGD Transport Path features and pgRouting
  • RESOURCES
    • 🆕Data Visualisation External Resources
Powered by GitBook

Website

  • Ordnance Survey

Data

  • OS Data Hub
On this page
  • Introduction
  • What do you need?
  • Method

Was this helpful?

  1. Tutorials
  2. GIS

Visualising a road gradient using a Digital Terrain Model

PreviousCreating a Digital Terrain Model (DTM)NextVisualising a road gradient using OSMM Highways

Last updated 1 year ago

Was this helpful?

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 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.

This is a little more hands on!! Open the Terrain Profile plugin by clicking this button:

Creating a Digital Terrain Model
The GML roadlinks will look something like this in QGIS
The expression builder window
Save the selected road
The A30
Examples of lines to delete
The Dissolve GUI
Your QGIS session should resemble this
Road slope calculator in the Toolbox window
The Road Slope Calculator GUI
The layer properties symbology tab filled out
The road styled according to gradient
The Terrain Profile graph window
The QGIS session view