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.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);
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
GDALAllRegister();
//Process the spatial reference conversions
//Set the Destination
srTmpPtr = SanitizeSRS("EPSG:4326");
sr = CSLSetNameValue(sr, "DST_SRS", srTmpPtr);
CPLFree(srTmpPtr);
//Set the Originating
srTmpPtr = SanitizeSRS("EPSG:32633");
sr = CSLSetNameValue(sr, "SRC_SRS", srTmpPtr);
CPLFree(srTmpPtr);
//Create a transformation object from the source to destination coordinate system.
transformer = GDALGenImgProjTransform;
transformArg = GDALCreateGenImgProjTransformer2( srcDS, dstDS, sr );
//Clean Up
CSLDestroy(sr);
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 3: Call Stack with symbols downloaded:
-- 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.
gdal-data
directory from GDAL correctly, and set theGDAL_DATA
environment variable? Does your program work if you copy thegdal-data
directory from GDAL into the same directory as your program?