[gdal-dev] GDAL.Net 2.3.1 - CoordinateTransformation mismatch....

Morten Breiner morten at breiner.dk
Sun Mar 10 15:24:55 PDT 2019


Hi,

I hope that I am posting my question to the right mailing list.

Currently, I am investigating the use of GDAL.NET 2.3.1 installed as a 
NUGET package in VisualStudio 2017.

It works very well when it comes to reading geotiff using provided 
drivers etc. However, when it comes to performing a coordinate 
transformation from one geodesy to another I encounter a mismatch 
between actual and expected coordinates. I have illustrated this in the 
Test Method below, where I have tried to transform a coordinate from 
EPSG:32028 to EPSG:4326, my test fails the final two Asserts.AreEqual 
when testing "x" and "y".

[TestMethod]

publicvoidGdalTransformEPSG32028ToEPSG4326()

{

// Setting environment variables and load all GDAL and OGR drivers

GdalConfiguration.ConfigureGdal();

GdalConfiguration.ConfigureOgr();

stringverInfo = Gdal.VersionInfo(string.Empty);

Assert.IsTrue(String.Compare(verInfo, "GDAL 2.3.1, released 2018/06/22", 
StringComparison.Ordinal)==0);

SpatialReference spatialSrc = newSpatialReference(string.Empty);

spatialSrc.ImportFromEPSG(32028);

SpatialReference spatialDest = newSpatialReference(string.Empty);

spatialDest.ImportFromEPSG(4326);

CoordinateTransformation transformator = 
newCoordinateTransformation(spatialSrc, spatialDest);

double[] result = newdouble[3];

transformator.TransformPoint(result, 2397350, 386280, 0);

// Actual output:  x=-76.3056550480934,  y=41.2177849636383,  z=0.0

// EPSG.io output: x=-76.3053142,        y=41.217868

Assert.AreEqual(-76.3053142, result[0], 1e-6, "x"); // failure 
x=-76.3056550480934

Assert.AreEqual(41.217868, result[1], 1e-6, "y"); // failure y= 
41.2177849636383

}


The static method GdalConfiguration() configure paths for proj lib, 
drivers etc as illustrated below:

///<summary>

///Construction of Gdal/Ogr

///</summary>

staticGdalConfiguration()

{

varexecutingAssemblyFile = 
newUri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;

varexecutingDirectory = Path.GetDirectoryName(executingAssemblyFile);

if(string.IsNullOrEmpty(executingDirectory))

thrownewInvalidOperationException("cannot get executing directory");

vargdalPath = Path.Combine(executingDirectory, "gdal");

varnativePath = Path.Combine(gdalPath, GetPlatform());

// Prepend native path to environment path, to ensure the

// right libs are being used.

varpath = Environment.GetEnvironmentVariable("PATH");

path = nativePath + ";"+ Path.Combine(nativePath, "plugins") + ";"+ path;

Environment.SetEnvironmentVariable("PATH", path);

// Set the additional GDAL environment variables.

vargdalData = Path.Combine(gdalPath, "data");

Environment.SetEnvironmentVariable("GDAL_DATA", gdalData);

Gdal.SetConfigOption("GDAL_DATA", gdalData);

vardriverPath = Path.Combine(nativePath, "plugins");

Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", driverPath);

Gdal.SetConfigOption("GDAL_DRIVER_PATH", driverPath);

Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData);

Gdal.SetConfigOption("GEOTIFF_CSV", gdalData);

varprojSharePath = Path.Combine(gdalPath, "share");

Environment.SetEnvironmentVariable("PROJ_LIB", projSharePath);

Gdal.SetConfigOption("PROJ_LIB", projSharePath);

}

///<summary>

///Method to ensure the static constructor is being called.

///</summary>

///<remarks>Be sure to call this function before using 
Gdal/Ogr/Osr</remarks>

publicstaticvoidConfigureOgr()

{

if(_configuredOgr) return;

// Register drivers

Ogr.RegisterAll();

_configuredOgr = true;

PrintDriversOgr();

}

///<summary>

///Method to ensure the static constructor is being called.

///</summary>

///<remarks>Be sure to call this function before using 
Gdal/Ogr/Osr</remarks>

publicstaticvoidConfigureGdal()

{

if(_configuredGdal) return;

// Register drivers

Gdal.AllRegister();

_configuredGdal = true;

PrintDriversGdal();

}

I would expect that I do the GDAL initialisation correctly, including 
the coordinate transformation but the "wrong" result when comparing my 
results with http://epsg.io or similar sources indicate that I am 
missing something essential? I have spent a long time trying to find a 
solution to this issue, but with out result.

Looking forward to receive any suggestion of what might be wrong in my 
approach.

Many thanks in advance.

BR

-Morten Breiner


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190310/7b5383fb/attachment-0001.html>


More information about the gdal-dev mailing list