Skip to content

Commit

Permalink
Merge pull request #59835 from qgis/backport-59819-to-release-3_40
Browse files Browse the repository at this point in the history
[Backport release-3_40] Fix CRS exception when fallback operation occurs, fix invalid CRS transform for status bar display
  • Loading branch information
alexbruy authored Dec 12, 2024
2 parents 68dfbb1 + 47f5f3c commit b183529
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/app/qgsstatusbarcoordinateswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ void QgsStatusBarCoordinatesWidget::refreshMapCanvas()
void QgsStatusBarCoordinatesWidget::showMouseCoordinates( const QgsPointXY &p )
{
mLastCoordinate = p;
mLastCoordinateCrs = mMapCanvas->mapSettings().destinationCrs();
updateCoordinateDisplay();
}

Expand Down Expand Up @@ -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<int>( mMousePrecisionDecimalPlaces ) ) );
mLineEdit->setText( QgsCoordinateUtils::formatCoordinateForProject( QgsProject::instance(), mLastCoordinate, mLastCoordinateCrs, static_cast<int>( mMousePrecisionDecimalPlaces ) ) );

ensureCoordinatesVisible();
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsstatusbarcoordinateswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class QgsMapCanvas;

#include "qgis_app.h"
#include "qgspointxy.h"
#include "qgscoordinatereferencesystem.h"

#include <QWidget>
#include <QElapsedTimer>
Expand Down Expand Up @@ -87,6 +88,7 @@ class APP_EXPORT QgsStatusBarCoordinatesWidget : public QWidget
unsigned int mMousePrecisionDecimalPlaces;

QgsPointXY mLastCoordinate;
QgsCoordinateReferenceSystem mLastCoordinateCrs;

bool mIsFirstSizeChange = true;
QElapsedTimer mLastSizeChangeTimer;
Expand Down
14 changes: 7 additions & 7 deletions src/core/proj/qgscoordinatetransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down

0 comments on commit b183529

Please sign in to comment.