[gdal-dev] exportToProj4

Paul Meems bontepaarden at gmail.com
Sat Jan 25 14:50:10 PST 2014

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?

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20140125/4392ec9d/attachment.html>

More information about the gdal-dev mailing list