0

I am working on a project to convert between one coordinate system, provided by an EPSG code, and EPSG:4326 or EPSG:4979 (WGS84 CS to include heights above ellipsoid).

Testing the following coordinates in British National Grid, EPSG:27700 using gdal transform and epsg.io generates the same results:

x = 330231.2515625854;
y = 376174.72374993574;
z = -7.352000006675735;

gdaltransform returns the correct results, apart from the elevation which is something I'll be looking into at a later date - the lat/long are the important values at the moment.

gdaltransform -s_srs epsg:27700 -t_srs epsg:4979
Enter X Y [Z [T]] values separated by space, and press Return.
330231.2515625854 376174.72374993574 -7.352000006675735
-3.04778889624274 53.2779570544652 -7.35200000667573

epsg.io also returns the same results as above https://epsg.io/transform#s_srs=27700&t_srs=4979&x=330231.2515626&y=376174.7237499

gdaltransform and epsg.io also return the same results for epsg:4236.

I have implemented GDAL using C#, .NET 7, using the MaxRev.Gdal.Core package.

When using this the results are incorrect:

    GdalBase.ConfigureAll();
    Ogr.RegisterAll();

    var x = 330231.25156258536;
    var y = 376174.72374993586;
    var z = -7.352000006675735;

    var epsg27700 = 27700;
    var epsg4979 = 4979; // same result for 4326


    var inputCS= new SpatialReference(null);
    inputCS.ImportFromEPSG(epsg27700);

    var wgs84 = new SpatialReference(null);
    wgs84.ImportFromEPSG(epsg4979);

    var ct = new CoordinateTransformation(inputCS, wgs84);
    var transformed = new double[3];
    ct.TransformPoint(transformed, x, y, z);
    Console.WriteLine($"long: {transformed[0]}, lat: {transformed[1]}, z: {transformed[2]}");

Which returns:

long: -3.047789419352417, lat: 53.277941280668884, z: -7.352000006675735

The correct values are:

long: -3.04778889624274, lat: 53.2779570544652, z: -7.35200000667573

This is just over a meter difference.

Does anyone know what I might be doing wrong here?

5
  • With GDAL 3.7.0dev-5ce7ba068f, released 2023/01/17 and Proj Rel. 8.2.0, November 1st, 2021 the result is -3.04778941935242 53.2779412806689 -7.35200000667573. So pretty close to the "wrong" result. I believe that your programs are having different Proj versions and transformation parameters. I would trust the newest version but if you have independent reference data that the result is wrong. In that case I would file a Proj issue into bug tracker.
    – user30184
    Jan 25, 2023 at 15:23
  • Thanks that's really helpful, are those results from using gdaltransform? I'm unsure if I need to add some sort of shift as EPSG:4979 needs handling in the vertical datum
    – TJames
    Jan 25, 2023 at 15:51
  • 1
    I noticed that my GDAL 3.7.0dev was missing a grid shift file "uk_os_OSTN15_NTv2_OSGBtoETRS.tif". Maybe you have the same issue.
    – user30184
    Jan 25, 2023 at 16:18
  • Gotcha, that could be it, I can't seem to find where Gdal Net installs the grid shift files but this points me in the right direction!
    – TJames
    Jan 25, 2023 at 16:37
  • 1
    @user30184, you were right - Gdal Net didn't reference this file, I added this and it works as expected. Thanks for your time!
    – TJames
    Jan 25, 2023 at 16:59

1 Answer 1

2

As mentioned in the comments, the issue was due to Gdal Net not including the grid shift files. Adding a reference to these using Proj.Configure("path/to/grid_shift/dir"); fixed the issue.

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.