[gdal-dev] Help: No coordinate conversion using OGRSpatialReference/OGRCoordinateTransformation in version 2.2.3

Davide De Marchi davide.demarchi at yahoo.it
Mon Jan 15 23:25:34 PST 2018




 Dear GDAL list,
I'm having problems using the standard way to convert coordinate points from a source to a target SRS. After updating to version 2.2.3, code that always worked started to leave the input coordinate unchanged, without giving any error or warning.This is the code I use:
bool ConvertPoint(int InputEPSG, int OutputEPSG, double *x, double *y){ bool res = false;
 OGRSpatialReference oSourceSRS, oTargetSRS; OGRCoordinateTransformation *poCT;     if( oSourceSRS.importFromEPSG(InputEPSG)  != OGRERR_NONE ) printf("OGRSpatialReference failed to importFromEPSG %d.\n",InputEPSG);  if( oTargetSRS.importFromEPSG(OutputEPSG) != OGRERR_NONE ) printf("OGRSpatialReference failed to importFromEPSG %d.\n",OutputEPSG); 
 poCT = OGRCreateCoordinateTransformation(&oSourceSRS, &oTargetSRS); if( !poCT )   {    printf("OGRCreateCoordinateTransformation failed.\n");    return false;   }
 double z = 0.0;
 if( !poCT->Transform(1,x,y,&z) ) printf("Transformation failed.\n"); else res = true;
 delete poCT; return res;}
If I call, for instance:
double x = 12.5;double y = 43.0;ConvertPoint(4326, 32633, &x, &y);
x and y remain unchanged and no error or warning is printed.
I tried to change the function by looking at the code of gdaltransform app:
bool ConvertPoint(int InputEPSG, int OutputEPSG, double *x, double *y){ bool res = false;
 GDALTransformerFunc pfnTransformer = nullptr; void               *hTransformArg; int                 bInverse = FALSE; char              **papszTO  = nullptr;
 char fromBuffer[100], toBuffer[100]; sprintf(fromBuffer,"EPSG:%d",InputEPSG); sprintf(toBuffer,  "EPSG:%d",OutputEPSG);
 char *pszFROM = SanitizeSRS(fromBuffer); papszTO = CSLSetNameValue(papszTO, "SRC_SRS", pszFROM); CPLFree(pszFROM);
 char *pszTO = SanitizeSRS(toBuffer); papszTO = CSLSetNameValue(papszTO, "DST_SRS", pszTO); CPLFree(pszTO);
 pfnTransformer = GDALGenImgProjTransform; hTransformArg = GDALCreateGenImgProjTransformer2(nullptr, nullptr, papszTO); CSLDestroy(papszTO); if( hTransformArg == nullptr )   {    printf("GDALCreateGenImgProjTransformer2 failed.\n");    return false;   }
 double z = 0.0;
 int bSuccess = TRUE; if( pfnTransformer(hTransformArg, bInverse, 1, x, y, &z, &bSuccess ) && bSuccess ) res = true; else printf("Transformation failed.\n");
 GDALDestroyGenImgProjTransformer(hTransformArg);
 return res;}
In this case everything works well and the coordinates are transformed.
What I'm doing wrong in my first original function?Any hints?
Thank you!
Davide De Marchi (JRC European Commission)

   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20180116/ad881b21/attachment.html>


More information about the gdal-dev mailing list