[gdal-dev] exportToProj4

Paul Meems bontepaarden at gmail.com
Sat Jan 25 16:27:30 PST 2014


Thanks Even,

This seems to be working. But unfortunately we have projection code in
several places, like
https://mapwingis.codeplex.com/SourceControl/latest#MapWinGIS/trunk/Processing/Projections.cppand
https://mapwingis.codeplex.com/SourceControl/latest#MapWinGIS/trunk/Grid/tkGridRaster.cpp(around
like 440).

I tried to use your suggestion in all those places, but it does compile but
doesn't run.
I'll need to let a true C++ developer look at it ;)

Thanks,



Paul

 *Paul Meems *
Release manager, configuration manager
and forum moderator of MapWindow GIS.
www.mapwindow.org

Owner of MapWindow.nl - Support for
Dutch speaking users.
www.mapwindow.nl




2014-01-26 Even Rouault <even.rouault at mines-paris.org>

> 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 **
> > prj4)
> >     {
> >         FILE * pFile;
> >         pFile = fopen (prjfileName,"r");
> >         if (pFile == NULL)
> >         {
> >             // Doesn't exist
> >             return;
> >         }
> >         fclose(pFile);
> >         pFile = NULL;
> >         OGRSpatialReference* oSRS = new OGRSpatialReference();
> >
> >         char **papszPrj = CSLLoad(prjfileName);
> >         if (papszPrj == NULL)
> >         {
> >             return;
> >         }
> >
> >         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);
> >         CPLFree(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
> deallocation with
>
> oSRS = (OGRSpatialReference*)OSRNewSpatialReference(NULL);
>
> and
>
> OGRSpatialReference::DestroySpatialReference(oSRS)
>
> >
> > Thanks for any advice.
> >
> > Paul
> >
> > *Paul Meems *
> > Release manager, configuration manager
> > and forum moderator of MapWindow GIS.
> > www.mapwindow.org
> >
> > Owner of MapWindow.nl - Support for
> > Dutch speaking users.
> > www.mapwindow.nl
>
> --
> Geospatial professional services
> http://even.rouault.free.fr/services.html
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20140126/a9d7d54e/attachment-0001.html>


More information about the gdal-dev mailing list