[gdal-dev] Create a ISpatialReference from an SpatialReference
Frank Warmerdam
warmerdam at pobox.com
Sat Nov 17 10:27:58 PST 2012
Xavier,
You haven't indicated your target language.
On 12-11-17 08:22 AM, xavier lhomme wrote:
> Hi
>
> How to get the EPSG Code from a OSR.SpatialReference ?
In C++ you could do something like:
int nPCS = -1;
if( poSRS->GetAuthorityName("PROJCS") != NULL
&& EQUAL(poSRS->GetAuthorityName("PROJCS"),"EPSG") )
{
nPCS = atoi(poSRS->GetAuthorityCode("PROJCS"));
}
This works for projected coordinate systems. For geographic
coordinate systems you could replace PROJCS with GEOGCS.
I would add that for coordinate systems without existing AUTHORITY
entries with the EPSG codes it can be helpful to run the
AutoIdentifyEPSG() method on the OGRSpatialReference. This will make
a somewhat feeble attempt to recognise EPSG coordinate systems and
attach the authority codes.
> Is there some explample to create an ESRI ISpatialReference from a
> OSR.SpatialReference ?
I am not familiar with ISpatialReference, but with an OGRSpatialReference
you can call morphToESRI() to switch the coordinate system definition
format to match what is expected by the ArcGIS Projection Engine and
then fetch the string out with ExportToWkt(). In Python this might look
something like:
srs = ogr.SpatialReference()
srs.ImportFromEPSG(4202)
srs.MorphToESRI()
pe_wkt = srs.ExportToWkt()
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://home.gdal.org/warmerda
and watch the world go round - Rush | Geospatial Software Developer
More information about the gdal-dev
mailing list