Skip to content

Commit

Permalink
best_only: move warning at the PJ* level
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 12, 2023
1 parent 5dd7d1f commit 0a0cc0b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
22 changes: 13 additions & 9 deletions src/4D_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,13 @@ static void warnAboutMissingGrid(PJ* P)
"Consult https://proj.org/resource_files.html for guidance.";
}
}
if( P->ctx->warnIfBestTransformationNotAvailable )
if( !P->errorIfBestTransformationNotAvailable &&
P->warnIfBestTransformationNotAvailable )
{
msg += " This might become an error in a future PROJ major release. "
"Set the ONLY_BEST option to YES or NO. "
"This warning will no longer be emitted (for the current context).";
P->ctx->warnIfBestTransformationNotAvailable = false;
"This warning will no longer be emitted (for the current transformation instance).";
P->warnIfBestTransformationNotAvailable = false;
}
pj_log(P->ctx,
P->errorIfBestTransformationNotAvailable ? PJ_LOG_ERROR : PJ_LOG_DEBUG,
Expand Down Expand Up @@ -384,7 +385,7 @@ similarly, but prefers the 2D resp. 3D interfaces if available.
return res;
}
else if( P->errorIfBestTransformationNotAvailable ||
P->ctx->warnIfBestTransformationNotAvailable ) {
P->warnIfBestTransformationNotAvailable ) {
warnAboutMissingGrid(alt.pj);
if( P->errorIfBestTransformationNotAvailable )
return res;
Expand Down Expand Up @@ -1941,6 +1942,7 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons
double accuracy = -1;
bool allowBallparkTransformations = true;
bool forceOver = false;
bool warnIfBestTransformationNotAvailable = true;
bool errorIfBestTransformationNotAvailable = ctx->errorIfBestTransformationNotAvailableDefault;
for (auto iter = options; iter && iter[0]; ++iter) {
const char *value;
Expand All @@ -1959,7 +1961,7 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons
return nullptr;
}
} else if ((value = getOptionValue(*iter, "ONLY_BEST="))) {
ctx->warnIfBestTransformationNotAvailable = false;
warnIfBestTransformationNotAvailable = false;
if( ci_equal(value, "yes") )
errorIfBestTransformationNotAvailable = true;
else if( ci_equal(value, "no") )
Expand Down Expand Up @@ -2018,7 +2020,7 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons
proj_operation_factory_context_set_grid_availability_use(
ctx, operation_ctx,
(errorIfBestTransformationNotAvailable ||
ctx->warnIfBestTransformationNotAvailable ||
warnIfBestTransformationNotAvailable ||
proj_context_is_network_enabled(ctx)) ?
PROJ_GRID_AVAILABILITY_KNOWN_AVAILABLE:
PROJ_GRID_AVAILABILITY_DISCARD_OPERATION_IF_MISSING_GRID);
Expand All @@ -2041,14 +2043,15 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons
ctx->forceOver = forceOver;

const int old_debug_level = ctx->debug_level;
if( errorIfBestTransformationNotAvailable || ctx->warnIfBestTransformationNotAvailable )
if( errorIfBestTransformationNotAvailable || warnIfBestTransformationNotAvailable )
ctx->debug_level = PJ_LOG_NONE;
PJ* P = proj_list_get(ctx, op_list, 0);
ctx->debug_level = old_debug_level;
assert(P);

if( P != nullptr ) {
P->errorIfBestTransformationNotAvailable = errorIfBestTransformationNotAvailable;
P->warnIfBestTransformationNotAvailable = warnIfBestTransformationNotAvailable;
}

if( P == nullptr || op_count == 1 ||
Expand All @@ -2059,7 +2062,7 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons

if( P != nullptr &&
(errorIfBestTransformationNotAvailable ||
ctx->warnIfBestTransformationNotAvailable) &&
warnIfBestTransformationNotAvailable) &&
!proj_coordoperation_is_instantiable(ctx, P) )
{
warnAboutMissingGrid(P);
Expand All @@ -2075,7 +2078,7 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons
return P;
}

if( errorIfBestTransformationNotAvailable || ctx->warnIfBestTransformationNotAvailable )
if( errorIfBestTransformationNotAvailable || warnIfBestTransformationNotAvailable )
ctx->debug_level = PJ_LOG_NONE;
auto preparedOpList = pj_create_prepared_operations(ctx, source_crs, target_crs,
op_list);
Expand All @@ -2093,6 +2096,7 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons
for( auto& op: preparedOpList ) {
op.pj->over = forceOver;
op.pj->errorIfBestTransformationNotAvailable = errorIfBestTransformationNotAvailable;
op.pj->warnIfBestTransformationNotAvailable = warnIfBestTransformationNotAvailable;
}

// If there's finally juste a single result, return it directly
Expand Down
1 change: 0 additions & 1 deletion src/ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ pj_ctx::pj_ctx(const pj_ctx& other) :
lastFullErrorMessage(std::string()),
last_errno(0),
debug_level(other.debug_level),
warnIfBestTransformationNotAvailable(other.warnIfBestTransformationNotAvailable),
errorIfBestTransformationNotAvailableDefault(other.errorIfBestTransformationNotAvailableDefault),
logger(other.logger),
logger_app_data(other.logger_app_data),
Expand Down
2 changes: 1 addition & 1 deletion src/proj_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ struct PJconsts {
std::vector<PJCoordOperation> alternativeCoordinateOperations{};
int iCurCoordOp = -1;
bool errorIfBestTransformationNotAvailable = false;
bool warnIfBestTransformationNotAvailable = true; /* to remove in PROJ 10? */

/*************************************************************************************
Expand Down Expand Up @@ -695,7 +696,6 @@ struct pj_ctx{
std::string lastFullErrorMessage{}; // used by proj_context_errno_string
int last_errno = 0;
int debug_level = PJ_LOG_ERROR;
bool warnIfBestTransformationNotAvailable = true; /* to remove in PROJ 10? */
bool errorIfBestTransformationNotAvailableDefault = false;
void (*logger)(void *, int, const char *) = nullptr;
void *logger_app_data = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions test/cli/tv_out.dist
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,11 @@ Attempt to use coordinate operation Inverse of WGS 84 to EGM2008 height (1) fail
49 2 0 * * inf
##############################################################
Test cs2cs (grid missing) with PROJ_ONLY_BEST_DEFAULT=YES
Attempt to use coordinate operation Inverse of WGS 84 to EGM2008 height (1) failed. Grid us_nga_egm08_25.tif is not available. Consult https://proj.org/resource_files.html for guidance. This might become an error in a future PROJ major release. Set the ONLY_BEST option to YES or NO. This warning will no longer be emitted (for the current context).
Attempt to use coordinate operation Inverse of WGS 84 to EGM2008 height (1) failed. Grid us_nga_egm08_25.tif is not available. Consult https://proj.org/resource_files.html for guidance.
49 2 0 * * inf
##############################################################
Test cs2cs (grid missing) with only_best_default=on in proj.ini
Attempt to use coordinate operation Inverse of WGS 84 to EGM2008 height (1) failed. Grid us_nga_egm08_25.tif is not available. Consult https://proj.org/resource_files.html for guidance. This might become an error in a future PROJ major release. Set the ONLY_BEST option to YES or NO. This warning will no longer be emitted (for the current context).
Attempt to use coordinate operation Inverse of WGS 84 to EGM2008 height (1) failed. Grid us_nga_egm08_25.tif is not available. Consult https://proj.org/resource_files.html for guidance.
49 2 0 * * inf
##############################################################
Test cs2cs --only-best (grid missing)
Expand Down

0 comments on commit 0a0cc0b

Please sign in to comment.