[Gdal-dev] proj4/wkt --> epsg
Mateusz Loskot
mateusz at loskot.net
Mon Jul 10 06:53:05 EDT 2006
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.
I hope it helps or may be anyone knows a better way?
Cheers
--
Mateusz Loskot
http://mateusz.loskot.net
More information about the Gdal-dev
mailing list