[gdal-dev] How get EPSG code from an OGRSpatialReferenceH?

Even Rouault even.rouault at spatialys.com
Fri Aug 29 10:45:22 PDT 2014


Le vendredi 29 août 2014 05:20:16, David Strip a écrit :
> It's my recollection from a question I posted here  a little over a year
> ago that except for a few special cases, autoIdentifyEPSG only works if
> there is an authority node providing the EPSG.

Hu, no. That would make it really useless. AutoIdentifyEPSG() tries to add 
EPSG authority and code on a very restricted set of common SRS that don't have 
it

> Hopefully someone will
> give you an authoritative answer. I believe GeoTools has the capability
> to find the EPSG from the WKT, but I have no idea how to interface to that
> 
> On 8/28/2014 8:42 PM, Nik Sands wrote:
> > Hi devs,
> > 
> > What is the correct way to extract the EPSG code from an
> > OGRSpatialReferenceH ?
> > 
> > Currently I'm finding that the following works only for SRS of some images 
and not others:
> > 	const char *charAuthType = OSRGetAttrValue(gdal.srcSRS, "AUTHORITY", 0);
> > 	const char *charSrsCode = OSRGetAttrValue(gdal.srcSRS, "AUTHORITY", 1);
> > 
> > However, there is no "AUTHORITY" node in some SRSs so it doesn't work for 
those images.  To cater for this, I'm trying to explicitly set the authority 
node using:
> > 	OSRAutoIdentifyEPSG(gdal.srcSRS);
> > 
> > But this fails with OGRERR_UNSUPPORTED_SRS (even when it is an SRS that
> > GDAL recognises and uses well).

Yes, this is expected. There are just a few SRS definitions that are encoded in 
it.

> > 
> > So I'm stumped... how do I reliably determine the EPSG for an
> > OGRSpatialReferenceH?

There's no real reliable way of doing that. There are approximative methods to 
get a best match. For example you could iterate on EPSG codes with 
importFromEPSG() and exportToProj4(), and compare with exportToProj4() on your 
WKT, but you can easily find situations where several EPSG SRS resolve to the 
same proj4 string.
Anyway, there's currently no such ready-made heuristics method in GDAL, 
although it might be useful to have one ultimately.

> > 
> > Cheers,
> > Nik.
> > 
> > _______________________________________________
> > gdal-dev mailing list
> > gdal-dev at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/gdal-dev
> 
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list