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

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Nik Sands-2
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).

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

Cheers,
Nik.

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How get EPSG code from an OGRSpatialReferenceH?

David Strip-2
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. 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).
>
> So I'm stumped... how do I reliably determine the EPSG for an OGRSpatialReferenceH?
>
> Cheers,
> Nik.
>
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How get EPSG code from an OGRSpatialReferenceH?

Even Rouault-2
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
> > [hidden email]
> > http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How get EPSG code from an OGRSpatialReferenceH?

David Strip-2
On 8/29/2014 11:45 AM, Even Rouault wrote:
> 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
>
Isn't that what I wrote?
"few special cases" = "very restricted set" ?
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How get EPSG code from an OGRSpatialReferenceH?

Even Rouault-2
Le vendredi 29 août 2014 19:52:57, David Strip a écrit :

> On 8/29/2014 11:45 AM, Even Rouault wrote:
> > 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
>
> Isn't that what I wrote?
> "few special cases" = "very restricted set" ?

Sorry. Appears I read your sentence to fast and missed that "except for a few
specifal cases".


--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How get EPSG code from an OGRSpatialReferenceH?

Nik Sands-2
In reply to this post by Even Rouault-2
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 <[hidden email]> 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
>>> [hidden email]
>>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>> _______________________________________________
>> gdal-dev mailing list
>> [hidden email]
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev