0

I'll preface this question with the statement I know very little about projection systems so this is coming from a position of total ignorance.

I have two shapefiles. One is in England and one is in Scotland, the Scottish one comes from a Scottish goverment website and when converted to geojson with https://github.com/calvinmetcalf/shapefile-js which uses proj4 under the hood, the polygons are several 100 meters offset from the basemap terrain beneath them. The English shapefile is 100% correct.

Upon inspecting the .prj files I can see subtle differences between their definitions:

English shapefile:

PROJCS["British_National_Grid",GEOGCS["GCS_OSGB_1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0.0],UNIT["Decimal_Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000.0],PARAMETER["False_Northing",-100000.0],PARAMETER["Central_Meridian",-2.0],PARAMETER["Scale_Factor",0.9996012717],PARAMETER["Latitude_Of_Origin",49.0],UNIT["Meter",1.0]]

Scottish shapefile:

PROJCS["British National Grid",GEOGCS["Ordnance Survey Great Brit",DATUM["Ordnance Survey Great Brit",SPHEROID["Airy 1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0.0],UNIT["Decimal_Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000.0],PARAMETER["False_Northing",-100000.0],PARAMETER["Central_Meridian",-2.0],PARAMETER["Scale_Factor",0.9996012717],PARAMETER["Latitude_Of_Origin",49.0],UNIT["Meter",1.0]]

The differences are:

Scotland -> England

SPHEROID["Airy 1830" -> SPHEROID["Airy_1830"

GEOGCS["Ordnance Survey Great Brit" -> GEOGCS["GCS_OSGB_1936"

PROJCS["British National Grid" -> PROJCS["British_National_Grid"

DATUM["Ordnance Survey Great Brit" -> DATUM["D_OSGB_1936"

If I simply replace the entire Scotland .prj file with the England .prj file it lines up perfectly

I then tried to work out exactly what part of the Scotland .prj file was causing the issue and I narrowed it down to:

DATUM["Ordnance Survey Great Brit"

If I just replace that with DATUM["D_OSGB_1936" then the polygons align with the terrain perfectly.

So now when I'm handling shapefile uploads I'm going to unzip and find and replace any mention of DATUM["Ordnance Survey Great Brit with DATUM["D_OSGB_1936".

I'm just wondering is that the correct way to approach it? And I wonder why the Scottish goverment would be exporting an incorrect shapefile config, or if I'm missing something and this is a proj4 error in parsing it?

1
  • the answer is probably not to reproject the files to WGS84 when they are in EPSG:27700 which is designed for this data
    – Ian Turton
    Jan 12, 2023 at 13:19

1 Answer 1

0

The fix for now is:

Using jszip package

// Find filename in list of zip files that has .prj extension
let prjFileName = Object.keys(zip.files).find((item) => item.endsWith(".prj"));

const prjFile = zip.file(prjFileName);

if (prjFile) {
  const prjFileContent = await prjFile.async("string");

  if (prjFileContent.includes('DATUM["Ordnance Survey Great Brit"')) {
    zip.file(
      prjFileName,
      prjFileContent.replace(
        'DATUM["Ordnance Survey Great Brit"',
        'DATUM["D_OSGB_1936"'
      )
    );
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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