@@ -830,6 +830,7 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
830
830
}
831
831
832
832
mFallbackOperationOccurred = false ;
833
+ bool errorOccurredDuringFallbackOperation = false ;
833
834
if ( actualRes != 0
834
835
&& ( 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
835
836
&& ( d->mAllowFallbackTransforms || mBallparkTransformsAreAppropriate ) )
@@ -854,13 +855,14 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
854
855
// So here just check proj_errno() for single point transform
855
856
if ( numPoints == 1 )
856
857
{
858
+ projResult = proj_errno ( transform );
857
859
// hmm - something very odd here. We can't trust proj_errno( transform ), as that's giving us incorrect error numbers
858
860
// (such as "failed to load datum shift file", which is definitely incorrect for a default proj created operation!)
859
861
// so we resort to testing values ourselves...
860
- projResult = std::isinf ( xprev[0 ] ) || std::isinf ( yprev[0 ] ) || std::isinf ( zprev[0 ] ) ? 1 : 0 ;
862
+ errorOccurredDuringFallbackOperation = std::isinf ( xprev[0 ] ) || std::isinf ( yprev[0 ] ) || std::isinf ( zprev[0 ] );
861
863
}
862
864
863
- if ( projResult == 0 )
865
+ if ( !errorOccurredDuringFallbackOperation )
864
866
{
865
867
memcpy ( x, xprev.data (), sizeof ( double ) * numPoints );
866
868
memcpy ( y, yprev.data (), sizeof ( double ) * numPoints );
@@ -885,25 +887,33 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
885
887
z[pos] = std::numeric_limits<double >::quiet_NaN ();
886
888
}
887
889
888
- if ( projResult != 0 )
890
+ if ( projResult != 0 || errorOccurredDuringFallbackOperation )
889
891
{
890
892
// something bad happened....
891
893
QString points;
892
894
895
+ const QChar delim = numPoints > 1 ? ' \n ' : ' ' ;
893
896
for ( int i = 0 ; i < numPoints; ++i )
894
897
{
895
- points += QStringLiteral ( " (%1, %2)\n " ).arg ( x [i], 0 , ' f' ).arg ( y [i], 0 , ' f' );
898
+ points += QStringLiteral ( " (%1, %2)" ).arg ( xprev [i], 0 , ' f' ).arg ( yprev [i], 0 , ' f' ) + delim ;
896
899
}
897
900
898
- const QString dir = ( direction == Qgis::TransformDirection::Forward ) ? QObject::tr ( " forward transform" ) : QObject::tr ( " inverse transform" );
901
+ const QString dir = ( direction == Qgis::TransformDirection::Forward ) ? QObject::tr ( " Forward transform" ) : QObject::tr ( " Inverse transform" );
899
902
900
- const QString msg = QObject::tr ( " %1 of\n "
901
- " %2"
902
- " Error: %3" )
903
+ #if PROJ_VERSION_MAJOR>=8
904
+ PJ_CONTEXT *projContext = QgsProjContext::get ();
905
+ const QString projError = !errorOccurredDuringFallbackOperation ? QString::fromUtf8 ( proj_context_errno_string ( projContext, projResult ) ) : QObject::tr ( " Fallback transform failed" );
906
+ #else
907
+ const QString projError = !errorOccurredDuringFallbackOperation ? QString::fromUtf8 ( proj_errno_string ( projResult ) ) : QObject::tr ( " Fallback transform failed" );
908
+ #endif
909
+
910
+ const QString msg = QObject::tr ( " %1 (%2 to %3) of%4%5Error: %6" )
903
911
.arg ( dir,
912
+ ( direction == Qgis::TransformDirection::Forward ) ? d->mSourceCRS .authid () : d->mDestCRS .authid (),
913
+ ( direction == Qgis::TransformDirection::Forward ) ? d->mDestCRS .authid () : d->mSourceCRS .authid (),
914
+ QString ( delim ),
904
915
points,
905
- projResult < 0 ? QString::fromUtf8 ( proj_errno_string ( projResult ) ) : QObject::tr ( " Fallback transform failed" ) );
906
-
916
+ projError );
907
917
908
918
// don't flood console with thousands of duplicate transform error messages
909
919
if ( msg != mLastError )
0 commit comments