From 94578ea8ff38f4bc6b1f6f52b80ecf7359f5dfc2 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 20 Feb 2019 18:04:35 +0100 Subject: CoordinateOperation: add a hasBallparkTransformation() method that can be used to know if it includes a very approximative transformation term --- src/4D_api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/4D_api.cpp') diff --git a/src/4D_api.cpp b/src/4D_api.cpp index 1b3374f3..4f13f238 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -1102,8 +1102,8 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char double north_lat = 0.0; const char* name = proj_get_name(op); - if( name && (strstr(name, "Null geographic offset") || - strstr(name, "Null geocentric translation")) ) + if( name && (strstr(name, "Ballpark geographic offset") || + strstr(name, "Ballpark geocentric translation")) ) { // Skip default transformations } -- cgit v1.2.3 From 1b8b720bb742a50815b70f2025d9e1d5378899b2 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 19 Mar 2019 12:56:33 +0100 Subject: proj_create_crs_to_crs: better deal with coordinates outside of bbox (fixes #1329) In case several coordinate operations are returned for a CRS to CRS transformation, we currently determine the one to use by selecting the first operation whose bounding box contains the input point. This commit adds a fallback case where after doing that first iteration and finding no appropriate candidate, we try again by selecting the first operation available that does not involve grid based transformations. --- src/4D_api.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/4D_api.cpp') diff --git a/src/4D_api.cpp b/src/4D_api.cpp index 4f13f238..d0b2748e 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -51,6 +51,7 @@ #include "proj/common.hpp" #include "proj/coordinateoperation.hpp" #include "proj/internal/internal.hpp" +#include "proj/internal/io_internal.hpp" using namespace NS_PROJ::internal; @@ -192,6 +193,8 @@ similarly, but prefers the 2D resp. 3D interfaces if available. direction = opposite_direction(direction); if( !P->alternativeCoordinateOperations.empty() ) { + // Do a first pass and select the first coordinate operation whose area + // of use is compatible with the input coordinate int i = 0; for( const auto &alt: P->alternativeCoordinateOperations ) { if( direction == PJ_FWD ) { @@ -223,6 +226,35 @@ similarly, but prefers the 2D resp. 3D interfaces if available. } i ++; } + + // In case we did not find an operation whose area of use is compatible + // with the input coordinate, then goes through again the list, and + // use the first operation that does not require grids. + i = 0; + for( const auto &alt: P->alternativeCoordinateOperations ) { + auto coordOperation = dynamic_cast< + NS_PROJ::operation::CoordinateOperation*>(alt.pj->iso_obj.get()); + if( coordOperation ) { + if( coordOperation->gridsNeeded(P->ctx->cpp_context ? + P->ctx->cpp_context->databaseContext.as_nullable() : + nullptr).empty() ) { + if( P->iCurCoordOp != i ) { + std::string msg("Using coordinate operation "); + msg += alt.name; + pj_log(P->ctx, PJ_LOG_TRACE, msg.c_str()); + P->iCurCoordOp = i; + } + if( direction == PJ_FWD ) { + return pj_fwd4d( coord, alt.pj ); + } + else { + return pj_inv4d( coord, alt.pj ); + } + } + } + i++; + } + proj_errno_set (P, EINVAL); return proj_coord_error (); } -- cgit v1.2.3 From c05a91da2e9e008d77bd148d4de62045f9f149c8 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 26 Mar 2019 14:34:13 +0100 Subject: path_append(): make it clear that nullptr deref cannot happen. Coverity CID 193530 --- src/4D_api.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/4D_api.cpp') diff --git a/src/4D_api.cpp b/src/4D_api.cpp index d0b2748e..81e16600 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -1365,6 +1365,7 @@ static char *path_append (char *buf, const char *app, size_t *buf_size) { pj_dealloc (buf); buf = p; } + assert(buf); /* Only append a semicolon if something's already there */ if (0 != buflen) -- cgit v1.2.3