[gdal-dev] GDAL (.NET) coordinate transformation via BETA2007

Carsten Lockenkötter carsten.lockenkoetter at gon.de
Wed Sep 4 09:45:40 PDT 2019


I have updated my C# application to use the GDAL 3.0.1 binaries from GISInternals.

Transform via EPSG:
       var src = new SpatialReference("");
       var dest = new SpatialReference("");
       string wkt = "POINT(2575957.917 5728085.530)";
       var geom = Geometry.CreateFromWkt(wkt);
                src.ImportFromEPSG(31466);
       dest.ImportFromEPSG(3857);
       var transform = new CoordinateTransformation(src, dest);
       geom.Transform(transform);
       geom.ExportToWkt(out string outWKT);

// "POINT (3993425.20096133 2326133.24005068)" --> completely wrong

With CPL_DEBUG=ON and PROJ_DEBUG=5, I get following information about this transformation:
[cid:image001.png at 01D5634F.A76F19A0]

Transform via proj4 string:
       src.ImportFromProj4(@"+proj=tmerc +lat_0=0 +lon_0=6 +k=1 +x_0=2500000 +y_0=0 +ellps=bessel +nadgrids={absolutePath}\BETA2007.gsb +units=m +no_defs +type=crs");
       dest.ImportFromEPSG(3857);
// "POINT (790104.712949148 6742818.48632016)" --> ok

Transform via proj4 +init (deprecated)
       src.ImportFromProj4("+init=epsg:31466");
       dest.ImportFromEPSG(3857);

// "POINT (790104.712949148 6742818.48632016)" --> ok

[cid:image002.png at 01D5634F.A76F19A0]

Via CMD:
[cid:image003.png at 01D56350.8F2D45A0]
--> ok

FME returns:
(790104.7129438451,6742818.485878875)

So transforming via EPSG (source and destination) is using a completely wrong transformation in .NET, right?
But why?

My preferred method to transform is only via EPSG. But what I have to do, that the SpatialReference objects get the right transformation?

Regards,
Carsten

Von: Schmitz, Uwe <uwe.schmitz at bezreg-koeln.nrw.de>
Gesendet: Donnerstag, 29. August 2019 10:30
An: Carsten Lockenkötter <carsten.lockenkoetter at gon.de>; gdal-dev at lists.osgeo.org
Betreff: AW: GDAL (.NET) coordinate transformation via BETA2007

Carsten,

are you shure that the grid is used during transformation?
I know nothing about the C# package, but in my own tests
the “not-found” case was often the cause for wrong results.
So I tend to almost always use an absolute path to
the grid file.
Due to historical reasons gdal silently ignores this error.

Ah, and I see that I put an extra +wktext at the end of the
arguments. Don’t know if it’s still necessary.

Regards
Uwe


Von: gdal-dev [mailto:gdal-dev-bounces at lists.osgeo.org] Im Auftrag von Carsten Lockenkötter
Gesendet: Dienstag, 27. August 2019 14:24
An: gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>
Betreff: [gdal-dev] GDAL (.NET) coordinate transformation via BETA2007

Hello,

because SQLServer can't transform geometries, i have developed a .NET library (C#) that transforms the geometries based on GDAL (NuGet Package GDAL.Native v2.4.2).
In principle, this also works.

If i transform from 31466 to 3857, i have an offset of about 1.5m because gdal transformed via Helmert, not via Beta2007.
If i transform the same geometrie via proj4 string to use my Beta2007.gsb file, i get a completly wrong geometry.

sample code to transform via epsg
Example:

                var inputGeom = "POINT (2529815.8 5642182.4)";

                GdalConfiguration.ConfigureOgr();

                var source = new SpatialReference("");
                var destination = new SpatialReference("");

                source.ImportFromEPSG(31466);
                destination.ImportFromEPSG(3857);

                CoordinateTransformation transform = new CoordinateTransformation(source, destination);
                Geometry ogrGeom = Geometry.CreateFromWkt(inputGeom);
                ogrGeom.Transform(transform);

                ogrGeom.ExportToWkt(out string outGeom);

                return outGeom;

value of outGeom:
                POINT (776704.423009968 6626706.00572367)

if i transform the same geometrie via FME with the CsmapReprojector, i get this (correct) coordinates:
(776702.2109972419,6626706.521023605)

FME used the gridfile Beta2007, GDAL not.
So i tried to transform my geometrie via proj4 string, where I have the possibility to specify the gridfile.
My gridfile Beta2007.gsb is located here: {ProjectRoot}\bin\Debug\gdal\share\Beta2007.gsb

Example:

                var inputGeom = "POINT (2529815.8 5642182.4)";

                GdalConfiguration.ConfigureOgr();

                var source = new SpatialReference("");
                var destination = new SpatialReference("");

                source.ImportFromProj4("+proj=tmerc +lat_0=0 +lon_0=6 +k=1 +x_0=2500000 +y_0=0 +ellps=bessel +nadgrids=@BETA2007.gsb<mailto:+nadgrids=@BETA2007.gsb>");
                destination.ImportFromEPSG(3857);

                CoordinateTransformation transform = new CoordinateTransformation(source, destination);
                Geometry ogrGeom = Geometry.CreateFromWkt(inputGeom);
                ogrGeom.Transform(transform);

                ogrGeom.ExportToWkt(out string outGeom);

                return outGeom;

value of outGeom:
                POINT (776787.364952423 6626930.71048604)


What i need:
Beta2007 Transformation via EPSG code, but i don't know, where i have to change it.
(optional) if i can't change the transformation via EPSG code via Gridfile, i need to know the correct proj4 string for my transformation.

Best regards,
Carsten

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190904/caca56ca/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 7138 bytes
Desc: image001.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190904/caca56ca/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 8933 bytes
Desc: image002.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190904/caca56ca/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 11316 bytes
Desc: image003.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190904/caca56ca/attachment-0005.png>


More information about the gdal-dev mailing list