even.rouault at mines-paris.org
Sat Jan 25 15:01:55 PST 2014
Le samedi 25 janvier 2014 23:50:10, Paul Meems a écrit :
> Hi all,
> Thanks to Tamas Szekeres we are now using his binaries from
> http://www.gisinternals.com/sdk/ with MapWinGIS, our mapping ActiveX.
> This has drastically simplified our build process and we are very grateful
> for Tamas' help.
> We're now struggling with some minor issues regarding our 'old' C++ code
> and the new binaries for GDAL, GEOS, Proj4, etc.
> Several of them I managed to solve, but I'm struggling with this one.
> We have code to read a prj file and get the Proj4 string:
> void ProjectionTools::GetProj4FromPRJFile(char * prjfileName, char **
> FILE * pFile;
> pFile = fopen (prjfileName,"r");
> if (pFile == NULL)
> // Doesn't exist
> pFile = NULL;
> OGRSpatialReference* oSRS = new OGRSpatialReference();
> char **papszPrj = CSLLoad(prjfileName);
> if (papszPrj == NULL)
> OGRErr eErr = oSRS->importFromESRI(papszPrj);
> if (eErr != OGRERR_NONE)
> OGRErr eErr = oSRS->importFromProj4(*papszPrj);
> CSLDestroy( papszPrj );
> char * pszProj4 = NULL;
> eErr = oSRS->exportToProj4( &pszProj4 );
> delete oSRS; <-- going wrong now
> *prj4 = new char[_tcslen(pszProj4)+1];
> strcpy(*prj4, pszProj4);
> This code was working for years, but now it crashes on delete oSRS;.
> I've been searching for examples of how to use exportToProj4() in C++ but
> can only find Python examples.
> And I'm not a C++ developer, just a C# developer :)
> How should I now free oSRS?
The code looks OK and there's no fundamental reason why it would not work any
longer. I highly suspect that you are running into a classical issue of a
mismatch between the compile flags used in your application and the ones used
by the GDAL built itself.
You could perhaps avoid that by letting GDAL do the allocation and
oSRS = (OGRSpatialReference*)OSRNewSpatialReference(NULL);
> Thanks for any advice.
> *Paul Meems *
> Release manager, configuration manager
> and forum moderator of MapWindow GIS.
> Owner of MapWindow.nl - Support for
> Dutch speaking users.
Geospatial professional services
More information about the gdal-dev