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 (mouse or trackpad only, it won't work with finger dragging) - try zooming in and moving your cursor over spot heights on the map to reveal the OS Terrain 50 elevation data for that location. Note how closely the data matches the spot heights on the map.

Easting Northing Elevation
     

Demo 2

Click or tap any two points on the map to get their locations and elevations. 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.

Location & elevation data will appear here...

Feel free to contact me at bobosola@gmail.com if you have any questions or ideas for improvements.