I'm new to GIS and have access to OS MasterMap Topography Layer data (UK).

I've got it loaded into PostGIS and am querying the polygons that I'm interested in (buildings). My understanding is the coordinates are using EPSG:27700 (OS national grid). I'm converting these to 4326 using ST_Transform when retrieving them from the database.

I'm plotting them on a map using MapBox GL JS, however there are consistently out of alignment with the buildings on the base map.

Image1 - Mapbox

Initially when I saw this, I just assumed it was a small difference in datasets, especially as the shapes are different.

However, when I use the OS vector tiles instead of the default tiles form Mapbox (using 3857 for the tiles as suggested in the OS demo) which are based on the OS MasterMap Topography layer (the same dataset that I'm using for my polygons), everything is still misaligned - but the shapes are correct.

Image2 - OS I'm assuming my mistake is somewhere in converting between the different standards.

I've tried passing 3857 to my call to ST_Transform, but then the polygons don't render at all.

Looking at the MapBox documentation, when it comes to plotting points / polygons on the map, they're expecting coordinates based on WGS84 (4326): https://docs.mapbox.com/mapbox-gl-js/api/geography/#lnglat

However, their documentation also states that they use EPSG:3857: https://docs.mapbox.com/help/glossary/projection/

Can anyone help with what I'm doing wrong / not understanding?

  • I used to have this misalignment issue. Case: Geoserver + vectortiles plugins, doing some proxy using php to query VT features (application/x-protobuf) from EPSG:4326 DB stored in postgis. It turned out that explicitly define srs:EPSG:3857 in the WMS request fixed my problem. In your case I guess your data must be misaligned somewhere along the way. BTW It will help people a lot if you describe a little bit more on how you do your query. – ranggalawe Jul 24 at 5:00
  • Do you have maps in EPSG:27700 coordinate system. Try using them as base maps and draw building without any conversion to see if they are misaligned? You can report results here. – omega_cancer Jul 26 at 6:03

This is simply a transformation issue...

In order to get the OS MasterMap Topography Layer polygons (EPSG:27700) to align with the basemap (EPSG:3857) you will need to reproject (ST_Transform) them using the latest OSTN15 transformation.

Most applications tend to use the basic PROJ.4 settings found on sites like epsg.io (http://epsg.io/27700). This will result in the offset you are seeing.

I will assume you are using PostGIS to transform from 27700 to 4326. In order to use/apply the OSTN15 transformation you will need update your database spatial reference settings:

  1. Download the OSTN15_NTv2_OSGBtoETRS.gsb transformation file from https://www.ordnancesurvey.co.uk/business-government/tools-support/os-net/for-developers
  2. Add the GSB file to your PostGIS proj folder, e.g. "C:\Program Files\PostgreSQL\12\share\contrib\postgis-3.0\proj".
  3. Update the spatial_ref_sys table.
UPDATE spatial_ref_sys
SET proj4text = '"+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs +nadgrids=OSTN15_NTv2_OSGBtoETRS.gsb"'
WHERE srid '27700';

You can then transform the data into WGS84 (EPSG:4326) as you were doing previously in order to see the aligned output in your Mapbox GL JS demo.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.