You need to get the ThinkGeo.Gdal nuget package (which includes the 3.9.1 version of GDAL)
Here is the button click that reads some values from a window, and converts them using the GDAL converter, as well as our current (well tested) Proj4 based converter.
private void Convert_OnClick(object sender, RoutedEventArgs e)
{
// Get the Input Coordinate
// This will be in the Source (Internal) coordinate system
double originalX = double.Parse(XCoordinate.Text);
double originalY = double.Parse(YCoordinate.Text);
// Prepare these coordinates for use in the GDAL converter
// They need to be stored in a Vertex array
Vertex inputPoint = new Vertex(originalX, originalY);
List<Vertex> vertices =
[
inputPoint
];
// Get the GDAL Projection Converter
// This is an extension of the ThinkGeo ProjectionConverter which is used (or a derivation of it)
// for all the conversions and projections needed. GDAL seems to handle the Grid Conversions (like NTv2)
// The big trick here was to obtain the NTv2.gsb file from Resources Canada, and drop it in the projlib folder
// for the runtime for GDAL
// To get the file
// https://webapp.csrs-scrs.nrcan-rncan.gc.ca/geod/data-donnees/transformations.php
// Sign in (or sign up) to register and accept the licence
// Copy the NTv2.gsb file to
// {application executable folder}\runtimes\win-x64\native\projlib
// Suffice to say there are many other *.gsb files all around the world, just find the one you need and drop it in there.
// Get the Input/Output reference identifiers
int internalSrid = int.Parse(InputSrid.Text);
int externalSrid = int.Parse(OutputSrid.Text);
// Get me a converter that will handle the conversion
GdalProjectionConverter gdalConverter = new GdalProjectionConverter(internalSrid, externalSrid);
gdalConverter.Open();
// Now the magic happens, convert it and display it
Vertex outputVertex = gdalConverter.ConvertToExternalProjection(vertices).First();
ThinkGeoX.Content = $"{outputVertex.X:F4}";
ThinkGeoY.Content = $"{outputVertex.Y:F4}";
// We have our own version of the Grid Conversions (Including the NTv2)
// We can use this as a test
// Our tool needs to know where the find the Grid Files,
// this sets that directory for it (this is the key so it can find the NTv2.gsb file)
string directory = Directory.GetCurrentDirectory();
Proj4WrapperFactory.ResourceDirectory = $"{directory}\\nad\\";
// Get a converter to handle our conversion
IProj4Wrapper wrapper = Proj4WrapperFactory.CreateProjection(internalSrid, externalSrid);
// Our wrapper works in tuples, it was easier for us
Tuple<double, double>[] points = new Tuple<double, double>[1];
points[0] = new Tuple<double, double>(originalX, originalY);
// Do it, and show it
Tuple<double, double>[] convertedPoints = wrapper.ConvertToExternalProjection(points);
Proj4X.Content = $"{convertedPoints[0].Item1:F4}";
Proj4Y.Content = $"{convertedPoints[0].Item2:F4}";
}
And a UTM (Zone 12) conversion
They look pretty close to me.
To get this all to work I need the correct *.gsb files for Canada. To get the Grid File you have to go to…
Resource Canada Signup Page
And sign up and accept the license
Once you get the NTv2.gsb file from Resources Canada, you need to place it in the Runtime folder for the GDAL Libraries, in my case…
C:\Users\chris\Source\repos\ThinkGeoSaveState\ThinkGeoSaveState\bin\Debug\net8.0-windows\runtimes\win-x64\native\projlib for my debug. Your final executable folder may vary.