Skip to content

Commit

Permalink
Fix proj_assign_context()/pj_set_ctx() with pipelines and alternative…
Browse files Browse the repository at this point in the history
… coord operations

Fixes OSGeo/gdal#1989

pj_set_ctx() only changes the context to the main object. It should also
recurse down to the steps of the pipeline and the alternative coordinate
operations hold in alternativeCoordinateOperations

In the GDAL use case with multithreaded reprojection, and objects being transferred
between thread, this would cause a failed coordinate transformation to affect
an unrelated transformation of another thread...
  • Loading branch information
rouault committed Nov 12, 2019
1 parent 67ee557 commit f970636
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ void pj_set_ctx( projPJ pj, projCtx ctx )
if (pj==nullptr)
return;
pj->ctx = ctx;
if( pj->is_pipeline )
{
pj_pipeline_assign_context_to_steps(pj, ctx);
}
for( const auto &alt: pj->alternativeCoordinateOperations )
{
pj_set_ctx(alt.pj, ctx);
}
}

/************************************************************************/
Expand Down
7 changes: 6 additions & 1 deletion src/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Thomas Knudsen, [email protected], 2016-05-20
#include "geodesic.h"
#include "proj.h"
#include "proj_internal.h"
#include "proj_experimental.h"

PROJ_HEAD(pipeline, "Transformation pipeline manager");
PROJ_HEAD(pop, "Retrieve coordinate value from pipeline stack");
Expand Down Expand Up @@ -136,7 +137,11 @@ static PJ_LPZ pipeline_reverse_3d (PJ_XYZ xyz, PJ *P);
static PJ_XY pipeline_forward (PJ_LP lp, PJ *P);
static PJ_LP pipeline_reverse (PJ_XY xy, PJ *P);


void pj_pipeline_assign_context_to_steps( PJ* P, PJ_CONTEXT* ctx )
{
for (int i = 1; i <= static_cast<struct pj_opaque*>(P->opaque)->steps; i++)
proj_assign_context(static_cast<struct pj_opaque*>(P->opaque)->pipeline[i], ctx);
}


static PJ_COORD pipeline_forward_4d (PJ_COORD point, PJ *P) {
Expand Down
2 changes: 2 additions & 0 deletions src/proj_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,8 @@ std::string pj_double_quote_string_param_if_needed(const std::string& str);
PJ *pj_create_internal (PJ_CONTEXT *ctx, const char *definition);
PJ *pj_create_argv_internal (PJ_CONTEXT *ctx, int argc, char **argv);

void pj_pipeline_assign_context_to_steps( PJ* P, PJ_CONTEXT* ctx );

/* classic public API */
#include "proj_api.h"

Expand Down

0 comments on commit f970636

Please sign in to comment.