From c6cca8e63463aa1c1706566b486c59bbcfc5f3e7 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 15 Jan 2025 22:39:15 +0100 Subject: [PATCH] proj_clone(): properly propagate errorIfBestTransformationNotAvailable and other flags from source object Fixes /~https://github.com/OSGeo/gdal/issues/11650 --- src/iso19111/c_api.cpp | 13 ++++++++++--- src/malloc.cpp | 13 +++++++++++++ src/proj_internal.h | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index acefc44201..08dd570f59 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -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) { @@ -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()); } @@ -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( @@ -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, diff --git a/src/malloc.cpp b/src/malloc.cpp index 401a0a11d2..3bab2c2b54 100644 --- a/src/malloc.cpp +++ b/src/malloc.cpp @@ -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() { /*****************************************************************************/ diff --git a/src/proj_internal.h b/src/proj_internal.h index e06e2e23e2..66843b6664 100644 --- a/src/proj_internal.h +++ b/src/proj_internal.h @@ -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) */