OS Terrain 50 Elevation Data in Rust & PHP

OS Logo

This page has two demos of my PHP code to read elevation data from the freely-available Ordnance Survey OS Terrain 50 data which provides elevation data for Great Britain. Rust code is also available.

So why use OS Terrain 50 data when SRTM data is readily available?

I should note that worldwide SRTM 30m data now exists. This was only available for the USA when I wrote my SRTM 90 code back in around 2010. I believe the 30m data is based on the original Shuttle data but has been backfilled and mixed with other data sources to provide the increased accuracy. I have no plans to write code for this data because the OS data better fits my needs.

The problem with using OS Terrain 50 data

OS Terrain 50 data is published in specific binary formats for consumption by specific software. It's also available as thousands of small ASCII CSV-like files which are messy and spacing-consuming to deal with. So I have written a small utility called osterrain50 which converts the OS ASCII data into one efficient binary data file. The file can be read in any language which supports binary file reads. So to get access to the data for use in (say) a web site, do this:

The Rust souce code for the command line application is also available on GitHub. Both the PHP & Rust repos have demo code showing how to to read the binary data file. They are both heavily commented to assist translation to other languages.

The code can also generate infill elevations every 50m between two or more locations (ideal for hike or ride elevation plotting). The Rust code in particular is extremely fast: on a 2020 Mac mini M1 it retrieved 18,485 elevations along a line between Niton Down (Isle of Wight) and Dùnan Mòr (Cape Wrath, Scotland) in just under 30ms. The PHP code (as demonstrated on this page) does the job in around 120ms on the same machine, which is pretty good considering it has the overhead of JavaScript calling the PHP code over HTTP.

OS Terrain 50 Demos

Demo 1

Here is a simple demo; try zooming in and mousing over spot heights (or tap-and-dragging them) to reveal the OS Terrain 50 elevation data for that location (a mouse is better here). Note how closely the retrieved elevation data matches the spot heights on the map.

Easting Northing Elevation
     
OS maps logo

Demo 2

Click or tap any two points on the map to draw a line between two locations and return the elevation heights for every 50m between the two points. Click a third time to start over again. Try zooming out and clicking two locations a long way apart. The result are returned very rapidly in all cases.

OS maps logo