[PROJ] Way to transform coordinates given an osgeo::proj::operation::CoordinateOperation?

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

[PROJ] Way to transform coordinates given an osgeo::proj::operation::CoordinateOperation?

Martin Desruisseaux-3

Hello

I'm trying to find the best way to transform coordinate tupples given an osgeo::proj::operation::CoordinateOperation instance. My current understanding is that I need to get a PJ object as below. Is that correct?

CoordinateOperationNNPtr operation = ...
PJ_CONTEXT *ctx = ...
PJ *pj = (ctx, operation);
// Then use PJ as documented in "getting started" guide.

If above is the right approach, looking at the source code of pj_obj_create, there is two things I would like to do differently:

  • Use an existing osgeo::proj::io::DatabaseContext instance.
  • Do not fallback on pj_new() if the main block could not create the PJ.

So would the following block be okay (I know if use an internal method call, but I didn't saw a way to avoid it yet):

DatabaseContext dbContext = ...;
auto formatter = PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_5, dbContext);
auto projString = coordop->exportToPROJString(formatter.get());
PJ *pj = pj_create_internal(ctx, projString.c_str());
// Done; do not touch to pj->iso_obj or pj->cpp_context.

Or is there a better way to "execute" a CoordinateOperation with C++ API?

    Thanks,

        Martin



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

Re: Way to transform coordinates given an osgeo::proj::operation::CoordinateOperation?

Even Rouault-2
On mercredi 9 octobre 2019 15:47:26 CEST Martin Desruisseaux wrote:

> Hello
>
> I'm trying to find the best way to transform coordinate tupples given an
> osgeo::proj::operation::CoordinateOperation instance. My current
> understanding is that I need to get a PJ object as below. Is that correct?
>
>     CoordinateOperationNNPtr operation = ...
>     PJ_CONTEXT *ctx = ...
>     PJ *pj = (ctx, operation);
>     // Then use PJ as documented in "getting started" guide.
>
> If above is the right approach, looking at the source code of
> pj_obj_create, there is two things I would like to do differently:
>
>   * Use an existing osgeo::proj::io::DatabaseContext instance.
>   * Do not fallback on pj_new() if the main block could not create the PJ.
>
> So would the following block be okay (I know if use an internal method
> call, but I didn't saw a way to avoid it yet):
>
>     DatabaseContext dbContext = ...;
>     auto formatter =
> PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_5,
> dbContext); auto projString = coordop->exportToPROJString(formatter.get());
> PJ *pj = pj_create_internal(ctx, projString.c_str());
>     // Done; do not touch to pj->iso_obj or pj->cpp_context.
>
> Or is there a better way to "execute" a CoordinateOperation with C++ API?

You have indeed to go to the C API, but use proj_create() instead of
pj_create_internal()

--
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: Way to transform coordinates given an osgeo::proj::operation::CoordinateOperation?

Martin Desruisseaux-3
Le 09/10/2019 à 16:19, Even Rouault a écrit :
> You have indeed to go to the C API, but use proj_create() instead of
> pj_create_internal()

Thanks. But looking at proj_create() source code, it seems to fetch its
own DatabaseContext (or maybe not, depending on PROJ string content).
Can I assume that the PROJ string will be such as proj_create() will not
need to fetch a DatabaseContext? Or alternatively is there a public API
for associating a DatabaseContext to a PJ_CONTEXT (if this is not a
wrong thing to do)?

If understand that a PJ object can be used by only one thread at a time.
But does PJ retains a reference to PJ_CONTEXT or DatabaseContext after
construction? In the later case, the requirement would be a little bit
stronger since I must ensure that no PJ constructed with the same
PJ_CONTEXT are used in same time, right?

     Martin


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

Re: Way to transform coordinates given an osgeo::proj::operation::CoordinateOperation?

Even Rouault-2
On mercredi 9 octobre 2019 16:36:10 CEST Martin Desruisseaux wrote:
> Le 09/10/2019 à 16:19, Even Rouault a écrit :
> > You have indeed to go to the C API, but use proj_create() instead of
> > pj_create_internal()
>
> Thanks. But looking at proj_create() source code, it seems to fetch its
> own DatabaseContext (or maybe not, depending on PROJ string content).

It should normally use the one of the PJ_CONTEXT.

> Can I assume that the PROJ string will be such as proj_create() will not
> need to fetch a DatabaseContext?

Yes, a PROJ pipeline string shouldn't open the database.

>
> If understand that a PJ object can be used by only one thread at a time.
> But does PJ retains a reference to PJ_CONTEXT or DatabaseContext after
> construction?

Yes

> In the later case, the requirement would be a little bit
> stronger since I must ensure that no PJ constructed with the same
> PJ_CONTEXT are used in same time, right?

Yes

Or use
void PROJ_DLL proj_assign_context(PJ* pj, PJ_CONTEXT* ctx);

--
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: Way to transform coordinates given an osgeo::proj::operation::CoordinateOperation?

Martin Desruisseaux-3
Le 09/10/2019 à 16:56, Even Rouault a écrit :
> Or use
> void PROJ_DLL proj_assign_context(PJ* pj, PJ_CONTEXT* ctx);

Thanks! I didn't saw that one. It should do the trick for the
multi-threading issue.

     Martin


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

Re: Way to transform coordinates given an osgeo::proj::operation::CoordinateOperation?

Even Rouault-2
On mercredi 9 octobre 2019 17:07:52 CEST Martin Desruisseaux wrote:
> Le 09/10/2019 à 16:56, Even Rouault a écrit :
> > Or use
> > void PROJ_DLL proj_assign_context(PJ* pj, PJ_CONTEXT* ctx);
>

> Thanks! I didn't saw that one. It should do the trick for the
> multi-threading issue.

Was recently moved from proj_experimental.h to proj.h


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