From 37868f5c077ed907533a1bf5afaa07623f1d949e Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 11 Dec 2024 16:33:44 +1000 Subject: [PATCH 1/2] When an error in a fallback operation occurs, ensure exception has correct input coordinates It was showing the inf/inf values from the failed transform, not the input coordinate --- src/core/proj/qgscoordinatetransform.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/proj/qgscoordinatetransform.cpp b/src/core/proj/qgscoordinatetransform.cpp index 44b9f371720a..e5736e85da1e 100644 --- a/src/core/proj/qgscoordinatetransform.cpp +++ b/src/core/proj/qgscoordinatetransform.cpp @@ -840,10 +840,13 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double * { projResult = 0; proj_errno_reset( transform ); + memcpy( x, xprev.data(), sizeof( double ) * numPoints ); + memcpy( y, yprev.data(), sizeof( double ) * numPoints ); + memcpy( z, zprev.data(), sizeof( double ) * numPoints ); proj_trans_generic( transform, direction == Qgis::TransformDirection::Forward ? PJ_FWD : PJ_INV, - xprev.data(), sizeof( double ), numPoints, - yprev.data(), sizeof( double ), numPoints, - zprev.data(), sizeof( double ), numPoints, + x, sizeof( double ), numPoints, + y, sizeof( double ), numPoints, + z, sizeof( double ), numPoints, useTime ? t.data() : nullptr, sizeof( double ), useTime ? numPoints : 0 ); // Try to - approximately - emulate the behavior of pj_transform()... // In the case of a single point transform, and a transformation error occurs, @@ -859,14 +862,11 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double * // hmm - something very odd here. We can't trust proj_errno( transform ), as that's giving us incorrect error numbers // (such as "failed to load datum shift file", which is definitely incorrect for a default proj created operation!) // so we resort to testing values ourselves... - errorOccurredDuringFallbackOperation = std::isinf( xprev[0] ) || std::isinf( yprev[0] ) || std::isinf( zprev[0] ); + errorOccurredDuringFallbackOperation = std::isinf( x[0] ) || std::isinf( y[0] ) || std::isinf( z[0] ); } if ( !errorOccurredDuringFallbackOperation ) { - memcpy( x, xprev.data(), sizeof( double ) * numPoints ); - memcpy( y, yprev.data(), sizeof( double ) * numPoints ); - memcpy( z, zprev.data(), sizeof( double ) * numPoints ); mFallbackOperationOccurred = true; } From 47f5f3c523bd1a7ba8de2602d6a8628fb25d4edb Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 11 Dec 2024 16:34:42 +1000 Subject: [PATCH 2/2] Fix an instance where the status bar coordinates are incorrectly transformed This can happen immediately after a project CRS change, as the last mouse coordinates are incorrectly considered to be in the new project CRS. --- src/app/qgsstatusbarcoordinateswidget.cpp | 3 ++- src/app/qgsstatusbarcoordinateswidget.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/qgsstatusbarcoordinateswidget.cpp b/src/app/qgsstatusbarcoordinateswidget.cpp index 0c4fd57b85d4..db316bdbda49 100644 --- a/src/app/qgsstatusbarcoordinateswidget.cpp +++ b/src/app/qgsstatusbarcoordinateswidget.cpp @@ -374,6 +374,7 @@ void QgsStatusBarCoordinatesWidget::refreshMapCanvas() void QgsStatusBarCoordinatesWidget::showMouseCoordinates( const QgsPointXY &p ) { mLastCoordinate = p; + mLastCoordinateCrs = mMapCanvas->mapSettings().destinationCrs(); updateCoordinateDisplay(); } @@ -431,7 +432,7 @@ void QgsStatusBarCoordinatesWidget::updateCoordinateDisplay() if ( mLastCoordinate.isEmpty() ) mLineEdit->clear(); else - mLineEdit->setText( QgsCoordinateUtils::formatCoordinateForProject( QgsProject::instance(), mLastCoordinate, mMapCanvas->mapSettings().destinationCrs(), static_cast( mMousePrecisionDecimalPlaces ) ) ); + mLineEdit->setText( QgsCoordinateUtils::formatCoordinateForProject( QgsProject::instance(), mLastCoordinate, mLastCoordinateCrs, static_cast( mMousePrecisionDecimalPlaces ) ) ); ensureCoordinatesVisible(); } diff --git a/src/app/qgsstatusbarcoordinateswidget.h b/src/app/qgsstatusbarcoordinateswidget.h index debae9cea5a1..44ca00cfe8cc 100644 --- a/src/app/qgsstatusbarcoordinateswidget.h +++ b/src/app/qgsstatusbarcoordinateswidget.h @@ -28,6 +28,7 @@ class QgsMapCanvas; #include "qgis_app.h" #include "qgspointxy.h" +#include "qgscoordinatereferencesystem.h" #include #include @@ -87,6 +88,7 @@ class APP_EXPORT QgsStatusBarCoordinatesWidget : public QWidget unsigned int mMousePrecisionDecimalPlaces; QgsPointXY mLastCoordinate; + QgsCoordinateReferenceSystem mLastCoordinateCrs; bool mIsFirstSizeChange = true; QElapsedTimer mLastSizeChangeTimer;