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 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 OS. 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 set your working directory:

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.

About these ads