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 methods but both times when it gets to the portion to translate it throws Unhandled exception at 0x00007ff62fb056d5 in GDALTestApp.exe: 0xC0000005: Access violation reading location 0x0000000000000000. I am using VS 2012 to run an compile.

Code Sample 1:

    OGRSpatialReference srFrom;
    srFrom.SetUTM(33, true);

    OGRSpatialReference srTo;

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

    double x1 = 1291784.057793292;
    double y1 = 2724159.114436987;

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

Sample 2:

    char **sr = nullptr;
    char *srTmpPtr = nullptr;
    GDALTransformerFunc transformer = nullptr;
    void *transformArg;
    GDALDatasetH srcDS = nullptr;
    GDALDatasetH dstDS = nullptr;
    double x1 = 1291784.057793292;
    double y1 = 2724159.114436987;
    double dfZ = 0.0;
    int bSuccess = TRUE;

    //Init the GDAL Lib

    //Process the spatial reference conversions
    //Set the Destination
    srTmpPtr = SanitizeSRS("EPSG:4326");
    sr = CSLSetNameValue(sr, "DST_SRS", srTmpPtr);

    //Set the Originating
    srTmpPtr = SanitizeSRS("EPSG:32633");
    sr = CSLSetNameValue(sr, "SRC_SRS", srTmpPtr);

    //Create a transformation object from the source to destination coordinate system. 
    transformer = GDALGenImgProjTransform;
    transformArg = GDALCreateGenImgProjTransformer2( srcDS, dstDS, sr );

    //Clean Up

    transformer(transformArg, FALSE, 1, &x1, &y1, &dfZ, &bSuccess);

Update -- Here is the list of requested files located in my GDAL_DATA directory: compdcs.csv coordinate_axis.csv cubewerx_extra.wkt datum_shift.csv ecw_cs.wkt egm08_25.gtx ellipsoid.csv epsg.wkt esri_extra.wkt esri_StatePlane_extra.wkt esri_Wisconsin_extra.wkt gcs.csv gcs.override.csv gdalicon.png GDALLogoBW.svg GDALLogoColor.svg GDALLogoGS.svg gdalvrt.xsd gdal_datum.csv geoccs.csv geos.dll gml_registry.xml gt_datum.csv gt_ellips.csv header.dxf inspire_cp_BasicPropertyUnit.gfs inspire_cp_CadastralBoundary.gfs inspire_cp_CadastralParcel.gfs inspire_cp_CadastralZoning.gfs netcdf_config.xsd nitf_spec.xml nitf_spec.xsd ogrvrt.xsd osmconf.ini ozi_datum.csv ozi_ellips.csv pci_datum.txt pci_ellips.txt pcs.csv pcs.override.csv pdalcpp.dll PDALManifest.xml PDALManifest2.xml pdal_util.dll prime_meridian.csv proj.dll projop_wparm.csv ruian_vf_ob_v1.gfs ruian_vf_st_uvoh_v1.gfs ruian_vf_st_v1.gfs ruian_vf_v1.gfs s57agencies.csv s57attributes.csv s57attributes_aml.csv s57attributes_iw.csv s57expectedinput.csv s57objectclasses.csv s57objectclasses_aml.csv s57objectclasses_iw.csv seed_2d.dgn seed_3d.dgn stateplane.csv trailer.dxf unit_of_measure.csv vdv452.xml vdv452.xsd vertcs.csv vertcs.override.csv

--Update 2: Call stack view: enter image description here

--Update 3: Call Stack with symbols downloaded:

enter image description here

-- Update 4: It appears that the coordTrans is returning a null pointer for some reason even though the code has been tested by other users and works.

-- Solution: The fix ended up being the missing proj.dll.

  • 1
    Your first example works for me on Linux and your code seems fine. Have you installed the gdal-data directory from GDAL correctly, and set the GDAL_DATA environment variable? Does your program work if you copy the gdal-data directory from GDAL into the same directory as your program? Jan 30 '18 at 12:23
  • @CandyGumdrop Update, so I actually did have that variable set. The directory contains 61 files. I can list them out in an update up top.
    – Josh
    Jan 30 '18 at 12:36
  • @CandyGumdrop No change if files are added directory into output directory either
    – Josh
    Jan 30 '18 at 12:43
  • Do you get any more information from the call stack when debugging in Visual Studio? Jan 30 '18 at 12:50
  • @CandyGumdrop I added the call stack image above. Does that help?
    – Josh
    Jan 30 '18 at 12:52

The problem is that GDAL needs to dynamically load the PROJ.4 library at runtime in order to use coordinate transformation functions, but PROJ.4 is not installed on your system. This is why the OGRCreateCoordinateTransformation failed with an error and returned NULL.

Windows builds of PROJ.4 are available as a package in the OSGeo4W software distribution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.