[PROJ] Equivalent of OSRSetFromUserInput in proj 6 API

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

[PROJ] Equivalent of OSRSetFromUserInput in proj 6 API

Nyall Dawson
Hi list,

While plugging away at the QGIS proj 6 upgrade I came across code
which uses OSRSetFromUserInput in order to convert any freeform string
to a coordinate reference system object.

Is there an equivalent of this in the proj 6 API I should be using
instead of this?

Nyall
_______________________________________________
PROJ mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/proj
Reply | Threaded
Open this post in threaded view
|

Re: Equivalent of OSRSetFromUserInput in proj 6 API

Even Rouault-2
On lundi 8 avril 2019 13:18:07 CEST Nyall Dawson wrote:
> Hi list,
>
> While plugging away at the QGIS proj 6 upgrade I came across code
> which uses OSRSetFromUserInput in order to convert any freeform string
> to a coordinate reference system object.
>
> Is there an equivalent of this in the proj 6 API I should be using
> instead of this?

proj_create() will be able to handle PROJ strings, WKT, AUTH:CODE, OGC URNs
and CRS names (like 'WGS84')

If you pass it a PROJ string that needs to be interpretated as a CRS, you need
to add " +type=crs" to it, otherwise it will be interpretated as a coordinate
operation.

Even

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

Re: Equivalent of OSRSetFromUserInput in proj 6 API

Nyall Dawson
On Mon, 8 Apr 2019 at 18:15, Even Rouault <[hidden email]> wrote:

>
> On lundi 8 avril 2019 13:18:07 CEST Nyall Dawson wrote:
> > Hi list,
> >
> > While plugging away at the QGIS proj 6 upgrade I came across code
> > which uses OSRSetFromUserInput in order to convert any freeform string
> > to a coordinate reference system object.
> >
> > Is there an equivalent of this in the proj 6 API I should be using
> > instead of this?
>
> proj_create() will be able to handle PROJ strings, WKT, AUTH:CODE, OGC URNs
> and CRS names (like 'WGS84')
>
> If you pass it a PROJ string that needs to be interpretated as a CRS, you need
> to add " +type=crs" to it, otherwise it will be interpretated as a coordinate
> operation.

Is there any way use proj_create with an EPSG code, but restrict the
results to CRS objects only (for those duplicate codes)?

Nyall

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

Re: Equivalent of OSRSetFromUserInput in proj 6 API

Even Rouault-2
On lundi 8 avril 2019 19:32:23 CEST Nyall Dawson wrote:
> On Mon, 8 Apr 2019 at 18:15, Even Rouault <[hidden email]>
wrote:

> > On lundi 8 avril 2019 13:18:07 CEST Nyall Dawson wrote:
> > > Hi list,
> > >
> > > While plugging away at the QGIS proj 6 upgrade I came across code
> > > which uses OSRSetFromUserInput in order to convert any freeform string
> > > to a coordinate reference system object.
> > >
> > > Is there an equivalent of this in the proj 6 API I should be using
> > > instead of this?
> >
> > proj_create() will be able to handle PROJ strings, WKT, AUTH:CODE, OGC
> > URNs
> > and CRS names (like 'WGS84')
> >
> > If you pass it a PROJ string that needs to be interpretated as a CRS, you
> > need to add " +type=crs" to it, otherwise it will be interpretated as a
> > coordinate operation.
>
> Is there any way use proj_create with an EPSG code, but restrict the
> results to CRS objects only (for those duplicate codes)?
>

Use proj_create(ctx, "urn:ogc:def:crs:EPSG::XXXX")

or proj_create_from_database(ctx, "EPSG", "XXXX", PJ_CATEGORY_CRS, false,
nullptr)

Even

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

Re: Equivalent of OSRSetFromUserInput in proj 6 API

Nyall Dawson
On Mon, 8 Apr 2019 at 19:42, Even Rouault <[hidden email]> wrote:

>
> On lundi 8 avril 2019 19:32:23 CEST Nyall Dawson wrote:
> > On Mon, 8 Apr 2019 at 18:15, Even Rouault <[hidden email]>
> wrote:
> > > On lundi 8 avril 2019 13:18:07 CEST Nyall Dawson wrote:
> > > > Hi list,
> > > >
> > > > While plugging away at the QGIS proj 6 upgrade I came across code
> > > > which uses OSRSetFromUserInput in order to convert any freeform string
> > > > to a coordinate reference system object.
> > > >
> > > > Is there an equivalent of this in the proj 6 API I should be using
> > > > instead of this?
> > >
> > > proj_create() will be able to handle PROJ strings, WKT, AUTH:CODE, OGC
> > > URNs
> > > and CRS names (like 'WGS84')
> > >
> > > If you pass it a PROJ string that needs to be interpretated as a CRS, you
> > > need to add " +type=crs" to it, otherwise it will be interpretated as a
> > > coordinate operation.
> >
> > Is there any way use proj_create with an EPSG code, but restrict the
> > results to CRS objects only (for those duplicate codes)?
> >
>
> Use proj_create(ctx, "urn:ogc:def:crs:EPSG::XXXX")
>
> or proj_create_from_database(ctx, "EPSG", "XXXX", PJ_CATEGORY_CRS, false,
> nullptr)

Ok - in either of these approaches I'd need to do some pre-processing
of the string in order to determine whether it's a "EPSG:####" format.

What I'm wondering is whether there's any benefit here of porting away
from calling OSRSetFromUserInput and then OSRExportToWkt, and whether
doing so would end up with me just re-implementing all the logic which
is present in OSRSetFromUserInput. (There's also a lot of extra logic
in place regarding setting GDAL_FIX_ESRI_WKT in certain
circumstances).

I guess I'm hoping you'll tell me that there's no benefit to porting
this code away from OSRSetFromUserInput, and I can just leave
everything as is ;)

Nyall
_______________________________________________
PROJ mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/proj
Reply | Threaded
Open this post in threaded view
|

Re: Equivalent of OSRSetFromUserInput in proj 6 API

Even Rouault-2
> Ok - in either of these approaches I'd need to do some pre-processing
> of the string in order to determine whether it's a "EPSG:####" format.
>
> What I'm wondering is whether there's any benefit here of porting away
> from calling OSRSetFromUserInput and then OSRExportToWkt, and whether
> doing so would end up with me just re-implementing all the logic which
> is present in OSRSetFromUserInput. (There's also a lot of extra logic
> in place regarding setting GDAL_FIX_ESRI_WKT in certain
> circumstances).

OSRSetFromUserInput() in GDAL master mostly relies on proj_create() or
proj_create_from_database() now. There is no more any GDAL_FIX_ESRI_WKT stuff
since ESRI WKT import/export has been re-implemented in PROJ itself.

There's indeed moderate interest in switching from OSRSetFromUserInput() to
proj_create(). But it could be interesting that with GDAL >= 2.5, you use
OSRExportToWktEx(hSRS, &pszWKT, apszOptions) with apszOptions[] = {
"FORMAT=WKT2_2018", nullptr } to export to WKT2. This will preserve more
metadata, and allow a few new projection methods that haven't been mapped to
WKT1.

Even

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
PROJ mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/proj