Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-3_40] Fix CRS exception when fallback operation occurs, fix invalid CRS transform for status bar display #59835

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading