OS Terrain 50 Elevation Data in Rust & PHP
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?
- the OS data is provided every 50m as opposed to SRTM's 90m data set
- the OS data has a 4m root mean square error compared with 9.73m RMSE for SRTM (though this figure varies wildly in different publications)
- the OS data matches UK OS map spot heights much more closely
- the OS data is updated annually from regular aerial surveys (SRTM data is basically static)
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:
- download the OS Terrain 50 ASCII data zip file
- download my command-line utility application as either: $ osterrain50 <path/to/downloaded_OS_data_zip_file>
- download my PHP data reader class and mini demo on GitHub
- Amend the example code in the mini demo to suit your need
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.
OS Terrain 50 Demos
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.
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.