How to view and query elevation models and other raster data

Since I wrote my post on the OS Terrain 50 digital terrain model I’ve had a steady stream of internet searches sending people to my blog. I’ve also had a couple of questions about using and viewing elevations models.

So if you’re new to GIS, here’s a digestible way to get information out of a digital terrain model (dtm), using OS Terrain 50 as an example.

You can download the OS Terrain 50 data from the Ordnance Survey (OS) for free, via their OpenData portal. The most useful format is the ASCII grid and GML. This dataset is available as individual tiles, which makes using it a little more difficult. If you’re in UK academia or education you can access OS and other data via the Edina portal.

To view and query the data I find QGIS excellent, better yet: the software is free and available for all major operating systems. When you install the software it also comes with GRASS, which I often use for analysis. You can read about GRASS in some of my other posts.

When you’ve downloaded the dataset, you’ll first need to unzip the archive. To make life more difficult the Ordnance Survey have also zipped the subtiles of each national grid square. If you only want to use one grid square you can obviously select the contents, right click and unzip… for many more it’s worth using a script. The following instructions are for use in a Linux terminal (command line). If you’re not a Linux user, don’t worry you can run Linux from a USB stick. Have a read about it here. When you’ve opened a terminal you’ll first of all need to navigate to your working directory (where you unzipped the main file):

cd ./directory

Next to unzip the files. After a quick internet search I found this:

find . -name "*.zip" -exec unzip {} \;

Which unzips recursive folders in the working directory to the working directory. When you’ve extracted all the files remove those we don’t need (all but the .asc files):

rm *.asc.aux.xml
rm *.gml
rm *.prj
rm *.xml

To merge these files use the raster menu in QGIS: raster/miscellaneous/merge. To merge all of Great Britain will take around 5 mins. This is a graphical version of the gdal merge routine, you can also use the tool via the command line. The file sizes can get quite large though, so best not to use local scale data for national presentation!

To add the downloaded dtm file to QGIS click on the ‘add raster layer’ button, you may be asked to define a projection for the OS data this is code 27700 (you can also set the project to this via settings or the button in the bottom right corner). When the file opens it’s likely to be a single shade of grey – don’t panic! The reason for this is you haven’t set any colour controls. To do this right click/properties in the layer window (or double left click). On the style tab set the contrast enhancement to ‘stretch to minmax’. You could also set colours here via the color (sic) map drop down box. Have an experiment, remember to click ‘apply’ after each change so you can see what it does. If you choose colormap (sic) in this drop down you can use the colormap (sic) tab (confusing, I know) and specify your own colour choices.

Be aware that the contrast enhancement applies to raster backdrop maps (like OS 250k) that you might use. So it’s best not to change the default, unless you want to end up with odd map colours…

I find the following plugins useful (remember to enable 3rd party repositories):

  • Value tool: gives the value of the active raster layer(s) where the mouse cursor is
  • Profile tool: plots a cross section you define
  • Point sampling tool: samples rasters for a given set of points
  • Raster calculator (already installed, accessed via the raster menu)
  • Contour: (from the raster menu) raster/extraction/contour

There are many many others!

To convert the files to something else you can either use gdal via the command line, or when you have files loaded in QGIS right click on the file and choose ‘save as’. To view the dtm in a 3D fly through you can use the GRASS tool NVIS.

Hopefully this gives you some tips to get started. Below is a quick look at the OS Terrain for Northern Great Britain, produced in the QGIS print composer and Scribus. Obviously, if you’re viewing the data in QGIS you can zoom in and out to any scale you please.

OS Terrain 50 produced using QGIS (copyright Michael Spencer)
OS Terrain 50 produced using QGIS.


    1. I have. Thanks to the joys of the Linux package management it all happened with very little input from me!

      QGIS has certainly come on leaps and bounds since I started using it in ~2010/11. They were dubious first steps back then! Fast forward a few years and a stable product has matured. Magic!

  1. I’m coding an an android app that I plan to use when flying a microlight. I can easily get aircraft height above mean sea level from the GPS altitude feed. I’d like to be able to get height above ground level, based on reading the OS Terrain 50 data – get the lat and long from the GPS, convert it to OS references (I believe that would be required), and read the elevation data for that particular point. Is there a way to read the Terrain50 data directly (only interested in elevation at a point) ? I can’t find anything explaining the file format. Lost of references to GQIS, but Ineed to write this app without resorting to third party libraries and applications – do you know of a way to do this, or a detailed description of the file formats involved?

  2. Did you manage to merge all the asc files for GB into a tiff in one go? I am getting errors when I try this in QGIS. It either fails with “the command line is too long” or a more generic “the process failed to start” depending on how many files I select. This happens whether I select individual files or the entire directory.

    Any ideas?



    1. Yes, I think so. Likely was using my work computer that has 8 GB of ram and an i5 processor running Ubuntu 12.04 and at the time QGIS 1.8 (probably). Are you using the QGIS merge tool? I’ve not seen it generate errors that blame the command line before.

      Just tried it at home, desktop has 4 GB ram and an old AMD Athlon processor running Ubuntu 12.04 and QGIS 2.2. Took 3 minutes 20 seconds to do all of Great Britain as per the instructions above.

      Hopefully you get some joy!

      1. Hi Michael, thanks for your assistance – I set up a VM with Ubuntu and QGIS and this worked flawlessly.
        It seems to be an issue on Windows versions (I tried Win 7 and XP) – I think QGIS builds a string of filenames to send to gdal_merge which is too long.
        Another reason to switch to Linux…

  3. I have 4 bands in my Terrain 50 in QGIs, what are these representing? when I use profile tool, it shows that they all are different elevation values!

    1. Hi Kirsty, apologies for the delay: I’ve been away.

      I can’t answer for your specific case, but I would guess you’ve another raster open at the same time? Drop me an email and I should be able to help you through it.

  4. Hi, I’ve been looking for someone in Scotland who uses QGIS but after emailing the “user group” and not getting any reply I was giving up hope and starting to look at other ways like using the height data in a programming language.

    However, now I’ve found this, I have an interesting project based on height data which I suspect might take someone like you who knows what they are doing about an hour, whereas it could take me weeks. On the other hand it might not be possible.

    If I explain, you’ll probably tell me very quickly. And whilst I need the map for some serious research, it is also quite a fun map and I’m really surprised no one else has done it!!

    Can you email me at calgacus a.t.

    1. Hi Mike,

      Thanks for your message. I’ve had a look through the QGIS UK user group and also the QGIS users mailing list and can’t find any emails from you at all, so I think you didn’t get a reply because your message didn’t get through.

      I’m currently exploring the option of doing some consultancy work and so would love to hear from you, my details are accessible from the about page.

      There is a Scottish QGIS user meeting in Oct 2014:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s