diff options
| author | Kristian Evers <kristianevers@gmail.com> | 2020-12-21 17:28:48 +0100 |
|---|---|---|
| committer | Kristian Evers <kristianevers@gmail.com> | 2020-12-21 17:28:48 +0100 |
| commit | 5aad0d25f8423b8b88a716d0333c7bd19f6184c7 (patch) | |
| tree | f0a248ef08fb51ef0ec29178ef41fd4168d4c85d /src/4D_api.cpp | |
| parent | c3efbd23a5bf26f1dfd5bc55ae3488d5665ace98 (diff) | |
| parent | 1cafe3e602d3f697c8d2daaa9b634f3ad23b0d53 (diff) | |
| download | PROJ-5aad0d25f8423b8b88a716d0333c7bd19f6184c7.tar.gz PROJ-5aad0d25f8423b8b88a716d0333c7bd19f6184c7.zip | |
Merge remote-tracking branch 'osgeo/master'
Diffstat (limited to 'src/4D_api.cpp')
| -rw-r--r-- | src/4D_api.cpp | 98 |
1 files changed, 68 insertions, 30 deletions
diff --git a/src/4D_api.cpp b/src/4D_api.cpp index d6eb901d..909c3c32 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -176,7 +176,8 @@ double proj_roundtrip (PJ *P, PJ_DIRECTION direction, int n, PJ_COORD *coord) { return HUGE_VAL; if (n < 1) { - proj_errno_set (P, EINVAL); + proj_log_error(P, _("n should be >= 1")); + proj_errno_set (P, PROJ_ERR_OTHER_API_MISUSE); return HUGE_VAL; } @@ -294,7 +295,7 @@ similarly, but prefers the 2D resp. 3D interfaces if available. if( iRetry > 0 ) { const int oldErrno = proj_errno_reset(P); if (proj_log_level(P->ctx, PJ_LOG_TELL) >= PJ_LOG_DEBUG) { - pj_log(P->ctx, PJ_LOG_DEBUG, proj_errno_string(oldErrno)); + pj_log(P->ctx, PJ_LOG_DEBUG, proj_context_errno_string(P->ctx, oldErrno)); } pj_log(P->ctx, PJ_LOG_DEBUG, "Did not result in valid result. " @@ -312,7 +313,7 @@ similarly, but prefers the 2D resp. 3D interfaces if available. } PJ_COORD res = direction == PJ_FWD ? pj_fwd4d( coord, alt.pj ) : pj_inv4d( coord, alt.pj ); - if( proj_errno(alt.pj) == PJD_ERR_NETWORK_ERROR ) { + if( proj_errno(alt.pj) == PROJ_ERR_OTHER_NETWORK_ERROR ) { return proj_coord_error (); } if( res.xyzt.x != HUGE_VAL ) { @@ -359,21 +360,14 @@ similarly, but prefers the 2D resp. 3D interfaces if available. } } - proj_errno_set (P, EINVAL); + proj_errno_set (P, PROJ_ERR_COORD_TRANSFM_NO_OPERATION); return proj_coord_error (); } - switch (direction) { - case PJ_FWD: - return pj_fwd4d (coord, P); - case PJ_INV: - return pj_inv4d (coord, P); - default: - break; - } - - proj_errno_set (P, EINVAL); - return proj_coord_error (); + if (direction == PJ_FWD) + return pj_fwd4d (coord, P); + else + return pj_inv4d (coord, P); } @@ -383,18 +377,43 @@ int proj_trans_array (PJ *P, PJ_DIRECTION direction, size_t n, PJ_COORD *coord) /****************************************************************************** Batch transform an array of PJ_COORD. + Performs transformation on all points, even if errors occur on some points. + + Individual points that fail to transform will have their components set to + HUGE_VAL + Returns 0 if all coordinates are transformed without error, otherwise - returns error number. + returns a precise error number if all coordinates that fail to transform + for the same reason, or a generic error code if they fail for different + reasons. ******************************************************************************/ size_t i; + int retErrno = 0; + bool hasSetRetErrno = false; + bool sameRetErrno = true; for (i = 0; i < n; i++) { + proj_context_errno_set(P->ctx, 0); coord[i] = proj_trans (P, direction, coord[i]); - if (proj_errno(P)) - return proj_errno (P); - } + int thisErrno = proj_errno(P); + if( thisErrno != 0 ) + { + if( !hasSetRetErrno ) + { + retErrno = thisErrno; + hasSetRetErrno = true; + } + else if( sameRetErrno && retErrno != thisErrno ) + { + sameRetErrno = false; + retErrno = PROJ_ERR_COORD_TRANSFM; + } + } + } - return 0; + proj_context_errno_set(P->ctx, retErrno); + + return retErrno; } @@ -500,9 +519,6 @@ size_t proj_trans_generic ( break; case PJ_IDENT: return nmin; - default: - proj_errno_set (P, EINVAL); - return 0; } /* Arrays of length==0 are broadcast as the constant 0 */ @@ -771,7 +787,7 @@ PJ *pj_create_internal (PJ_CONTEXT *ctx, const char *definition) { n = strlen (definition); args = (char *) malloc (n + 1); if (nullptr==args) { - proj_context_errno_set(ctx, ENOMEM); + proj_context_errno_set(ctx, PROJ_ERR_OTHER /*ENOMEM*/); return nullptr; } strcpy (args, definition); @@ -779,14 +795,14 @@ PJ *pj_create_internal (PJ_CONTEXT *ctx, const char *definition) { argc = pj_trim_argc (args); if (argc==0) { free (args); - proj_context_errno_set(ctx, PJD_ERR_NO_ARGS); + proj_context_errno_set(ctx, PROJ_ERR_INVALID_OP_MISSING_ARG); return nullptr; } argv = pj_trim_argv (argc, args); if (!argv) { free(args); - proj_context_errno_set(ctx, ENOMEM); + proj_context_errno_set(ctx, PROJ_ERR_OTHER /*ENOMEM*/); return nullptr; } @@ -821,14 +837,14 @@ indicator, as in {"+proj=utm", "+zone=32"}, or leave it out, as in {"proj=utm", if (nullptr==ctx) ctx = pj_get_default_ctx (); if (nullptr==argv) { - proj_context_errno_set(ctx, PJD_ERR_NO_ARGS); + proj_context_errno_set(ctx, PROJ_ERR_INVALID_OP_MISSING_ARG); return nullptr; } /* We assume that free format is used, and build a full proj_create compatible string */ c = pj_make_args (argc, argv); if (nullptr==c) { - proj_context_errno_set(ctx, ENOMEM); + proj_context_errno_set(ctx, PROJ_ERR_INVALID_OP /* ENOMEM */); return nullptr; } @@ -849,14 +865,14 @@ Same as proj_create_argv() but calls pj_create_internal() instead of proj_create if (nullptr==ctx) ctx = pj_get_default_ctx (); if (nullptr==argv) { - proj_context_errno_set(ctx, PJD_ERR_NO_ARGS); + proj_context_errno_set(ctx, PROJ_ERR_INVALID_OP_MISSING_ARG); return nullptr; } /* We assume that free format is used, and build a full proj_create compatible string */ c = pj_make_args (argc, argv); if (nullptr==c) { - proj_context_errno_set(ctx, ENOMEM); + proj_context_errno_set(ctx, PROJ_ERR_OTHER /*ENOMEM*/); return nullptr; } @@ -1286,10 +1302,24 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons } const char* authority = nullptr; + double accuracy = -1; + bool allowBallparkTransformations = true; for (auto iter = options; iter && iter[0]; ++iter) { const char *value; if ((value = getOptionValue(*iter, "AUTHORITY="))) { authority = value; + } else if ((value = getOptionValue(*iter, "ACCURACY="))) { + accuracy = pj_atof(value); + } else if ((value = getOptionValue(*iter, "ALLOW_BALLPARK="))) { + if( ci_equal(value, "yes") ) + allowBallparkTransformations = true; + else if( ci_equal(value, "no") ) + allowBallparkTransformations = false; + else { + ctx->logger(ctx->logger_app_data, PJ_LOG_ERROR, + "Invalid value for ALLOW_BALLPARK option."); + return nullptr; + } } else { std::string msg("Unknown option :"); msg += *iter; @@ -1303,6 +1333,14 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons return nullptr; } + proj_operation_factory_context_set_allow_ballpark_transformations( + ctx, operation_ctx, allowBallparkTransformations); + + if( accuracy >= 0 ) { + proj_operation_factory_context_set_desired_accuracy(ctx, operation_ctx, + accuracy); + } + if( area && area->bbox_set ) { proj_operation_factory_context_set_area_of_interest( ctx, |
