ProjNet4GeoAPI icon indicating copy to clipboard operation
ProjNet4GeoAPI copied to clipboard

Transform coordinates using nadgrids?

Open Lotto2 opened this issue 5 years ago • 12 comments

Hello,

i'm trying to improve coordinate transformation from 'Gauss-Kruger zone 2' to UTM32 by using a nadgrids file. the file is stored in the directory of the application.

i found a WKT with this EXTENSION and '+nadgrids=@null' so i tried to extend my WKT.

helas, no change of the output.

any clues to use a nadgrids file?

VB-Code:

Dim GK2WKT = "PROJCS[""DHDN / 3-degree Gauss-Kruger zone 2"",GEOGCS[""DHDN"",DATUM[""Deutsches_Hauptdreiecksnetz"",SPHEROID[""Bessel 1841"",6377397.155,299.1528128,AUTHORITY[""EPSG"",""7004""]],TOWGS84[598.1,73.7,418.2,0.202,0.045,-2.455,6.7],AUTHORITY[""EPSG"",""6314""]],PRIMEM[""Greenwich"",0,AUTHORITY[""EPSG"",""8901""]],UNIT[""degree"",0.0174532925199433,AUTHORITY[""EPSG"",""9122""]],AUTHORITY[""EPSG"",""4314""]],UNIT[""metre"",1,AUTHORITY[""EPSG"",""9001""]],PROJECTION[""Transverse_Mercator""],PARAMETER[""latitude_of_origin"",0],PARAMETER[""central_meridian"",6],PARAMETER[""scale_factor"",1],PARAMETER[""false_easting"",2500000],PARAMETER[""false_northing"",0],EXTENSION[""PROJ4"",""+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=2500000 +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs **+nadgrids=./BETA2007.gsb""**],AUTHORITY[""EPSG"",""31466""],AXIS[""X"",NORTH],AXIS[""Y"",EAST]]"

Dim csGK2 As GeoAPI.CoordinateSystems.ICoordinateSystem = _ 
    ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(GK2WKT)

Dim csUTM32 As GeoAPI.CoordinateSystems.ICoordinateSystem = _
    ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(32, True)

Dim ctfac_Wgs84_Gk2 As ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory = _
    New ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory()

Dim ct_Gk2_Utm As GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation = _
    ctfac_Gk2_Utm.CreateFromCoordinateSystems(csGK2, csUTM32)

Dim toPoint As Double() = ct_Gk2_Utm.MathTransform.Transform(New Double() {2405675.77, 5804339.69})

Lotto2 avatar May 22 '19 15:05 Lotto2

PROJ4 extension is not supported by ProjNet4GeoAPI at this time, I think.

airbreather avatar May 22 '19 15:05 airbreather

I'm hitting the same issue, in my case I need to transform GK4 to WGS84 using BETA2007.gsb gridfile. Is there any plan to implement this? Thanks!

ondrasvoboda avatar Aug 25 '20 10:08 ondrasvoboda

I needed the same transformation from GK to ETRS89/UTM, so here's some code to test: https://github.com/wo80/NTv2

Take a look at CoordinateTransformTest.cs to see how a grid file can be used.

wo80 avatar Oct 23 '20 22:10 wo80

Works great, thanks! Would be nice to have it integrated into NetTopologySuite.

ondrasvoboda avatar Oct 26 '20 15:10 ondrasvoboda

@wo80, well done, do you mind us merging your project into this project?

FObermaier avatar Oct 28 '20 07:10 FObermaier

@FObermaier not at all.

For a more feature complete version the CoordinateTransformationFactory extension methods have to be reviewed/extended, since they were just written to work with the German coordinate systems. Other CS combinations might not work as expected (I tested NAD27 <> NAD83 and there was a clear difference to what some online converters show, see TestNAD).

wo80 avatar Oct 28 '20 08:10 wo80

@wo80, I noticed that you are still working on it. Give us a hint when you think it is in a state for merging. Or would you like to do it yourself?

FObermaier avatar Oct 29 '20 08:10 FObermaier

@FObermaier I'll do a pull request.

wo80 avatar Oct 29 '20 08:10 wo80

@wo80, just noticed that WGS84->GK4 fails with "No support for transforming between the two specified coordinate systems", can also this transformation be supported? Isn't it just a matter of extending the IF inside CreateFromCoordinateSystems method?

ondrasvoboda avatar Oct 29 '20 11:10 ondrasvoboda

Seems that adding this part in there, does the trick:

else if (sourceCS is GeographicCoordinateSystem && targetCS is ProjectedCoordinateSystem)
{
	ct = factory.CreateFromCoordinateSystems(sourceCS, targetCS);

	var list = GetCoordinateTransformationList(ct);

	// list[0] = source geographic -> geocentric
	// list[1] =        geocentric -> target projected

	// Replace the geographic transform with our grid transformation.
	list[0] = CreateCoordinateTransformation((ICoordinateTransformation)list[0], grid, inverse);
}
else if (sourceCS is ProjectedCoordinateSystem && targetCS is GeographicCoordinateSystem)
{
	ct = factory.CreateFromCoordinateSystems(sourceCS, targetCS);

	var list = GetCoordinateTransformationList(ct);

	// list[0] = source projected -> geocentric
	// list[1] =        geocentric -> target geographic

	// Replace the geographic transform with our grid transformation.
	list[1] = CreateCoordinateTransformation((ICoordinateTransformation)list[1], grid, inverse);
}

ondrasvoboda avatar Oct 29 '20 11:10 ondrasvoboda

@ondrasvoboda thanks, I'll add it to the pull request.

wo80 avatar Oct 29 '20 12:10 wo80

cool, thanks

ondrasvoboda avatar Oct 29 '20 12:10 ondrasvoboda