[Gdal-dev] gdal to proj4 translation

Frank Warmerdam warmerdam at pobox.com
Thu Jul 24 11:25:03 EDT 2003


Amici Alessandro wrote:

> Frank,
> 
> i'm working on a DEM reader and i wuold be glad to use gdal and proj4
> as fromat and projection engines. my question is: is there an easy way to
> convert the gdal representation of the projections (the opengis format
> if i understand correctly) and the proj4 strings?
> 
> digging into the docs i found the OGRSpatialReference class, which looks
> like
> a good starting point, but is it the shortest path?

Alessandro,

A short path (in C++) from WKT string to PROJ.4 string would be:

#include "ogr_spatialref.h"

...

	OGRSpatialReference oSRS;
         char *pszWKT = pszWKTOriginal;
         char *pszProj4 = NULL;

         oSRS.importFromWkt( &pszWKT );
         if( oSRS.exportToProj4( &pszProj4 ) == CE_None )
         {
         }

Note that instead of explicitly handling PROJ.4 strings, you can just
instantiate an OGRCoordinateTransformation object with two coordinate systems
and it will take care of creating the PROJ.4 representations internally
where needed.  I would suggest you review the OGR Projections Tutorial:

   http://gdal.velocet.ca/projects/opengis/ogrhtml/osr_tutorial.html

Best regards,

-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent





More information about the Gdal-dev mailing list