[Gdal-dev] proj4/wkt --> epsg

Frank Warmerdam warmerdam at pobox.com
Mon Jul 10 09:20:40 EDT 2006


Mateusz Loskot wrote:
> Shoaib Burq wrote:
>> Hi, I was just wondering if there is a way to programatically convert
>> proj4 or wkt to and EPSG code in OSR?
> 
> One of possibilities I see is to import SRS to OGRSpatialReference:
> 
> char* pszWkt = "..."; // put here your SRS WKT definition
> 
> OGRSpatialReference srs;
> srs.exportToWkt( &pszWkt );
> 
> const char* pszTarget = 0;
> const char* pszAuthName = 0;
> const char* pszAuthCode = 0;
> 
> if (srs.IsProjected())
>    pszTarget = "PROJCS";
> else
>    pszTarget = "GEOGCS";
> 
> pszAuthName = srs.GetAuthorityName( pszTarget );
> if( NULL != pszAuthName )
> {
>    if( EQUAL( pszAuthName, "EPSG" ) )
>    {
>       pszAuthCode = srs.GetAuthorityCode( pszTarget );
>       if( NULL != pszAuthCode )
>       {
>            // XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>            // Here is the epsg code
>            int epsg = atoi(pszAuthCode);
>       }
>    }
> }
> 
> Similarly, you should be able to import SRS from PROJ.4 definition using
> OGRSpatialReference::importFromProj4().
> 
> I've not compiled this code above, it is a copy&paste with small
> modifications from ogr/ogr2gmlgeometry.cpp file, starting from line 235
> where I retrieve EPSG code to save it as a value of srsName - GML
> attribute.

Mateusz / Shoaib,

The above will work if there is an ESPG authority code in the WKT.
Unfortunately, if you import a definition from PROJ.4 there is no
indication of the epsg code, so there will be no epsg authority codes
in the WKT representation.

Generally speaking there is no good way to go from PROJ.4 to EPSG codes.

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    | President OSGF, http://osgeo.org




More information about the Gdal-dev mailing list