Coordinates Reprojection with GDAL

So I am trying to re-project a coordinate from WGS 84 / UTM zone 33N (Meters) to WGS 84 (DD). I have tried the below method but when it gets to the portion to translate it throws an Unhandled exception at 0x00007ff62fb056d5 in GDALTestApp.exe: 0xC0000005: Access violation reading location 0x0000000000000000. I am using VS 2012 to run an compile. GDAL_DATA directory is set and contains 61 files.

Code Sample 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
OGRSpatialReference srFrom;
    srFrom.SetWellKnownGeogCS("WGS84");
    srFrom.SetUTM(33, true);

    OGRSpatialReference srTo;
    srTo.SetWellKnownGeogCS("WGS84");

    OGRCoordinateTransformation* coordTrans = 
    OGRCreateCoordinateTransformation(&srFrom, &srTo);

    double x1 = 1291784.057793292;
    double y1 = 2724159.114436987;

    int reprojected = coordTrans->Transform(1, &x1, &y1);


Stack Trace:
https://i.stack.imgur.com/8aqHl.png
Last edited on
Caveat: I know nothing about this library.

However since there is an access violation where the address is a null pointer,
it would be a good idea to verify that OGRCreateCoordinateTransformation did not return a null pointer.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
OGRCoordinateTransformation* coordTrans = OGRCreateCoordinateTransformation(&srFrom, &srTo);

if( coordTrans == 0 ) 
{
     // error: OGRCreateCoordinateTransformation failed null pointer was returned
     // print out an error message
     // TO DO: identify the cause of the failure; try to fix it etc.
}

else 
{
     // try to use coordTrans to perform transformations
     // ...
}
Your right it does appear to be returning a null pointer
Registered users can post here. Sign in or register to post.