MaxRev-Dev / gdal.netcore

GDAL 3.x C#/F# bindings for .NET apps
MIT License
162 stars 36 forks source link

[BUG] PROJ: utm: Invalid latitude #147

Closed tonywres closed 3 months ago

tonywres commented 3 months ago

Describe the bug I have a simple point that I am attempting to transform from EPSG 4326 to EPSG 32755. It is failing with 'PROJ: utm: Invalid latitude'

To Reproduce

using MaxRev.Gdal.Core;
using OSGeo.OSR;

// Initialize GDAL
GdalBase.ConfigureAll();

// Define the source and target spatial references
SpatialReference srcSpatialRef = new SpatialReference("");
srcSpatialRef.ImportFromEPSG(4326); // WGS84

SpatialReference dstSpatialRef = new SpatialReference("");
dstSpatialRef.ImportFromEPSG(32755); // UTM zone 55S

CoordinateTransformation transformToUTM = new CoordinateTransformation(srcSpatialRef, dstSpatialRef);

// Coordinates to transform
double[] point = new double[] { 144.9631, -37.8136, 0 };

// Validate latitude and longitude
if (point[1] < -80 || point[1] > 84)
{
    Console.WriteLine("Invalid latitude for UTM transformation.");
    return;
}

// Perform the transformation
try
{
    transformToUTM.TransformPoint(point);
    Console.WriteLine($"Transformed coordinates: X = {point[0]}, Y = {point[1]}, Z = {point[2]}");
}
catch (Exception ex)
{
    Console.WriteLine($"Error during transformation: {ex.Message}");
}

Expected behavior According to copilot: When you run this code, it should output the transformed coordinates in the UTM zone 55S projection. The expected result should be something like: Transformed coordinates: X = 321921.45, Y = 5814192.55, Z = 0

Screenshots image

Environment information:

Additional context Hopefully this should be simple enough to follow. I had a problem in my system with this transformation and I'd really like to know the cause. If you need anything extra please let me know, or if this is something that I need to post to a GDAL forum please tell me where.

MaxRev-Dev commented 3 months ago

This is not a bug. GDAL changed default coordinate order starting 3.0. See https://github.com/MaxRev-Dev/gdal.netcore/issues/13#issuecomment-612490539