Skip to content

Commit 5733e3d

Browse files
committed
Use bool to track errors from fallback operations
1 parent b682d36 commit 5733e3d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/core/proj/qgscoordinatetransform.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -829,10 +829,8 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
829829
}
830830
}
831831

832-
// something which won't clash with Proj's real error codes!
833-
constexpr int PROJ_RESULT_FALLBACK_OPERATION_FAILED = -481516;
834-
835832
mFallbackOperationOccurred = false;
833+
bool errorOccurredDuringFallbackOperation = false;
836834
if ( actualRes != 0
837835
&& ( d->mAvailableOpCount > 1 || d->mAvailableOpCount == -1 ) // only use fallbacks if more than one operation is possible -- otherwise we've already tried it and it failed
838836
&& ( d->mAllowFallbackTransforms || mBallparkTransformsAreAppropriate ) )
@@ -857,13 +855,14 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
857855
// So here just check proj_errno() for single point transform
858856
if ( numPoints == 1 )
859857
{
858+
projResult = proj_errno( transform );
860859
// hmm - something very odd here. We can't trust proj_errno( transform ), as that's giving us incorrect error numbers
861860
// (such as "failed to load datum shift file", which is definitely incorrect for a default proj created operation!)
862861
// so we resort to testing values ourselves...
863-
projResult = std::isinf( xprev[0] ) || std::isinf( yprev[0] ) || std::isinf( zprev[0] ) ? PROJ_RESULT_FALLBACK_OPERATION_FAILED : 0;
862+
errorOccurredDuringFallbackOperation = std::isinf( xprev[0] ) || std::isinf( yprev[0] ) || std::isinf( zprev[0] );
864863
}
865864

866-
if ( projResult == 0 )
865+
if ( !errorOccurredDuringFallbackOperation )
867866
{
868867
memcpy( x, xprev.data(), sizeof( double ) * numPoints );
869868
memcpy( y, yprev.data(), sizeof( double ) * numPoints );
@@ -888,7 +887,7 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
888887
z[pos] = std::numeric_limits<double>::quiet_NaN();
889888
}
890889

891-
if ( projResult != 0 )
890+
if ( projResult != 0 || errorOccurredDuringFallbackOperation )
892891
{
893892
//something bad happened....
894893
QString points;
@@ -903,9 +902,9 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
903902

904903
#if PROJ_VERSION_MAJOR>=8
905904
PJ_CONTEXT *projContext = QgsProjContext::get();
906-
const QString projError = projResult != PROJ_RESULT_FALLBACK_OPERATION_FAILED ? QString::fromUtf8( proj_context_errno_string( projContext, projResult ) ) : QObject::tr( "Fallback transform failed" );
905+
const QString projError = !errorOccurredDuringFallbackOperation ? QString::fromUtf8( proj_context_errno_string( projContext, projResult ) ) : QObject::tr( "Fallback transform failed" );
907906
#else
908-
const QString projError = projResult != PROJ_RESULT_FALLBACK_OPERATION_FAILED ? QString::fromUtf8( proj_errno_string( projResult ) ) : QObject::tr( "Fallback transform failed" );
907+
const QString projError = !errorOccurredDuringFallbackOperation ? QString::fromUtf8( proj_errno_string( projResult ) ) : QObject::tr( "Fallback transform failed" );
909908
#endif
910909

911910
const QString msg = QObject::tr( "%1 (%2 to %3) of%4%5Error: %6" )

0 commit comments

Comments
 (0)