TransWikia.com

Mapbox GL JS: Displaying polygons from different coordinate systems / projections

Geographic Information Systems Asked by gbuckingham89 on August 28, 2021

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?

One Answer

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 FilesPostgreSQL12sharecontribpostgis-3.0proj".
  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.

Correct answer by tmnnrs on August 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP