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

Nik Sands nixanz at nixanz.com
Fri Aug 29 15:14:29 PDT 2014


Thanks for the answer.  Not what I wanted to hear but such is life. (And I think it makes sense now that you explain it - ie, it's not a neatly reversible translation). 

It will complicate my user interface somewhat, but I think I've got an idea of how to work around it. 

Thanks,
Nik. 

On 30 Aug 2014, at 3:45 am, Even Rouault <even.rouault at spatialys.com> wrote:

>>> 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