[Gdal-dev] proj4/wkt --> epsg
Mateusz Loskot
mateusz at loskot.net
Mon Jul 10 09:30:33 EDT 2006
Frank Warmerdam wrote:
> 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.
Frank,
Thank you for your explanation.
Cheers
--
Mateusz Loskot
http://mateusz.loskot.net
More information about the Gdal-dev
mailing list