Getting started with OS Terrain 50 elevation data (updated Jan 2016)

The Ordnance Survey has recently updated their open data elevation product of Great Britain. OS Terrain 50 takes over from their still-available Land-Form PANORAMA product as the most up to date open data elevation product. This is of great use for large scale landscape visualisations, viewshed analysis, flood modelling, sampling height data for ecological surveys, map background layers and the like. The resolution of the data is 50m, hence ‘terrain 50’, and is in the Arc/Info ASCII Grid (.asc) format.

London elevation data with hypsometric tints, hill- and slope-shading. © Crown copyright and database right 2013

The data comes as a zip file containing a folder for each major OS grid square, further broken down in many (2,800+) zip files each containing a single 10 x 10km .asc elevation file. For example:

Unfortunately, even with a SSD drive, unzipping all the zip files, as recommended in the user guide, took around an hour and just under 1gb of disk space. Luckily, there is a way to keep these further zip files compressed after the first, main zip file has decompressed and create a single, lean file of the entire British Isles for quick and convenient use in your GIS using the Terminal and GDAL.

[see updated, alternative method below!]

The elevation data is ultimately stored in .asc files. I made a list of all the .asc file names stored within the zip folders by decompressing all the individual zip files then running the following command from the /data/ folder with the Terminal (OS X in my case):

find . -name "*.asc" > ~/GB.txt

this outputted a text file listing each individual .asc file. Here’s an excerpt:


To save yourself this time consuming stage, the text file I generated is available here (note to Ordnance Survey, it would be great if you provided something similar with future releases!). If you carried out the first step the unzipped folders can now be deleted. With a couple of find/replace commands within a text editor, the file paths were altered to


where ‘[path]’ is the file path to the terr50-gagg-gb folder. Note that ‘/vsizip//’ and the ‘.zip’ extension were included to allow GDAL to read the many individual .asc files whilst they remain zipped and combine them into a single ‘virtual raster’ mosaic. This edited .txt file can then be fed into GDAL build virtual raster program:

gdalbuildvrt -input_file_list ~/GB.txt ~/GB.vrt

After a very short time the resulting .vrt file is 1.3mb, and accesses the partially compressed terr50 folder that now only occupies 160mb or so disk space. Most importantly, the .vrt file loads into QGIS in a few seconds and can be used exactly like the .asc files would.

Update Jan 2016

I’ve updated my workflow using a single command to replace the previous steps. It requires a bit less effort (especially on linux) and doesn’t mind which edition of Terrain 50 you’re using. On the downside, it uses long, rather difficult to read command. If you get on okay with the old method, please keep on using it.

The following one line of code generates the text file required by gdalbuildvrt and is run on the main archive. That main archive then needs to be unzipped and its location needs to replace the your-file-path part of the code below. The code is easier to use on linux and requires a bit more work on OS X (as OS X uses a different version of sed that doesn’t allow changing lower to uppercase letters)

For linux:

zipinfo -1 | grep -E '[a-z]{2}[0-9]{2}' | sed -E 's|(.*)([a-z]{2}[0-9]{2})(.*)|/vsizip///your-file-path/terr50_gagg_gb/\1\2\3/\U\2\E.asc|' > ~/gb.txt

Then, as before, gdalbuildvrt -input_file_list ~/gb.txt ~/gb.vrt

For OS X:

zipinfo -1 | grep -E '[a-z]{2}[0-9]{2}' | sed -E 's|(.*)([a-z]{2}[0-9]{2})(.*)|/vsizip///your-file-path/terr50_gagg_gb/\1\2\3/\2.asc|' > ~/gb.txt

Now edit the text file in your editor of choice. Two letters will need to be made uppercase – ‘[…]tq01.asc’ to ‘[…]TQ01.asc’ at the end of every line. A programmers text editor or TextEdit on OS X with a ‘box selection’ function will help, or install gnu-sed with Homebrew and run the linux version of the sed substitution above with gsed – whichever is easier.

Then, as before, gdalbuildvrt -input_file_list ~/gb.txt ~/gb.vrt

Once again, for convenience, you can download a preprocessed version of the updated gb.txt here. If anyone has an easier method, please feel free to comment.