Skip to content

Commit

Permalink
Merge pull request #4382 from rouault/fix_gdal_11650
Browse files Browse the repository at this point in the history
proj_clone(): properly propagate errorIfBestTransformationNotAvailable and other flags from source object
  • Loading branch information
rouault authored Jan 17, 2025
2 parents 942cc65 + c6cca8e commit 1384b79
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ PJ *proj_clone(PJ_CONTEXT *ctx, const PJ *obj) {
if (newPj) {
newPj->descr = "Set of coordinate operations";
newPj->ctx = ctx;
newPj->copyStateFrom(*obj);
const int old_debug_level = ctx->debug_level;
ctx->debug_level = PJ_LOG_NONE;
for (const auto &altOp : obj->alternativeCoordinateOperations) {
Expand All @@ -569,7 +570,11 @@ PJ *proj_clone(PJ_CONTEXT *ctx, const PJ *obj) {
return nullptr;
}
try {
return pj_obj_create(ctx, NN_NO_CHECK(obj->iso_obj));
PJ *newPj = pj_obj_create(ctx, NN_NO_CHECK(obj->iso_obj));
if (newPj) {
newPj->copyStateFrom(*obj);
}
return newPj;
} catch (const std::exception &e) {
proj_log_error(ctx, __FUNCTION__, e.what());
}
Expand Down Expand Up @@ -9190,7 +9195,7 @@ PJ *proj_normalize_for_visualization(PJ_CONTEXT *ctx, const PJ *obj) {
pjNew->descr = "Set of coordinate operations";
pjNew->left = obj->left;
pjNew->right = obj->right;
pjNew->over = obj->over;
pjNew->copyStateFrom(*obj);

for (const auto &alt : obj->alternativeCoordinateOperations) {
auto co = dynamic_cast<const CoordinateOperation *>(
Expand Down Expand Up @@ -9226,8 +9231,10 @@ PJ *proj_normalize_for_visualization(PJ_CONTEXT *ctx, const PJ *obj) {
ctx->forceOver = alt.pj->over != 0;
auto pjNormalized =
pj_obj_create(ctx, co->normalizeForVisualization());
pjNormalized->over = alt.pj->over;
ctx->forceOver = false;

pjNormalized->copyStateFrom(*(alt.pj));

pjNew->alternativeCoordinateOperations.emplace_back(
alt.idxInOriginalList, minxSrc, minySrc, maxxSrc,
maxySrc, minxDst, minyDst, maxxDst, maxyDst,
Expand Down
13 changes: 13 additions & 0 deletions src/malloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ PJ *proj_destroy(PJ *P) {
PJconsts::PJconsts() : destructor(pj_default_destructor) {}
/*****************************************************************************/

/*****************************************************************************/
/* void PJconsts::copyStateFrom(const PJconsts& other) */
/*****************************************************************************/

void PJconsts::copyStateFrom(const PJconsts &other) {
over = other.over;
errorIfBestTransformationNotAvailable =
other.errorIfBestTransformationNotAvailable;
warnIfBestTransformationNotAvailable =
other.warnIfBestTransformationNotAvailable;
skipNonInstantiable = other.skipNonInstantiable;
}

/*****************************************************************************/
PJ *pj_new() {
/*****************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions src/proj_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ struct PJconsts {
PJconsts();
PJconsts(const PJconsts &) = delete;
PJconsts &operator=(const PJconsts &) = delete;

void copyStateFrom(const PJconsts &);
};

/* Parameter list (a copy of the +proj=... etc. parameters) */
Expand Down

0 comments on commit 1384b79

Please sign in to comment.