Fixing ONS Geoportal GeoJSON
I regularly use the ONS's Open Geography Portal (Geoportal). It is the place to get official mapping data for the UK. As I often make web-based maps, I regularly download the GeoJSON version of maps. However, as the years have gone on I've regularly run into issues.
The problems
The main problem is that the Geoportal's GeoJSON outputs seem to use the original (2008) GeoJSON definition. That means you get a file full of Eastings and Northings based on Ordnance Survey's National Grid and any polygons may use a left-hand rule for winding.
In 2016, the Internet Engineering Task Force (IETF) replaced the 2008 definition with a much stricter version. This 2016 version only allows WGS84 latitude/longitudes (because allowing every possible coordinate system made it hard for any tool that was going to render GeoJSON) and recommends the right-hand rule for winding. It is a shame that, in 2024, the ONS Geoportal still isn't using the 2016 GeoJSON definition.
Getting badly formatted GeoJSON files means that, in some tools/visualisations, the maps just don't render, areas go missing, or some areas are considered "broken".
The solution
I have previously contacted the Geoportal about this issue but didn't seem to get very far. Seeing no sign of any improvement from ESRI (who actually create the platform for ONS), I decided to make my own tool that will fix these GeoJSON issues.
Our ONS-GeoJSON-fixer tool uses GeoTools to go through all the Eastings and Northings and transform coordinates into longitudes and latitudes. The GeoTools algorithm for WGS84-OSGB36 conversions is derived from an OSGB spreadsheet (with permission) with conversion accuracy of the order of 7m for 90% of Great Britain. TheĀ ONS-GeoJSON-fixer then uses Placemark's geojson-rewind code to make sure the winding order of each polygon is correct.
These two steps should, hopefully, fix most issues in being able to use the Geoportal's GeoJSON output. I hope it is useful to others.
