diff --git a/src/core/proj/qgscoordinatetransform.cpp b/src/core/proj/qgscoordinatetransform.cpp index 2d18aa77e22c..0f510d0fb0b7 100644 --- a/src/core/proj/qgscoordinatetransform.cpp +++ b/src/core/proj/qgscoordinatetransform.cpp @@ -908,8 +908,10 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double * const QString projError = projResult != PROJ_RESULT_FALLBACK_OPERATION_FAILED ? QString::fromUtf8( proj_errno_string( projResult ) ) : QObject::tr( "Fallback transform failed" ); #endif - const QString msg = QObject::tr( "%1 of%2%3Error: %4" ) + const QString msg = QObject::tr( "%1 (%2 to %3) of%4%5Error: %6" ) .arg( dir, + ( direction == Qgis::TransformDirection::Forward ) ? d->mSourceCRS.authid() : d->mDestCRS.authid(), + ( direction == Qgis::TransformDirection::Forward ) ? d->mDestCRS.authid() : d->mSourceCRS.authid(), QString( delim ), points, projError ); diff --git a/tests/src/python/test_qgscoordinatetransform.py b/tests/src/python/test_qgscoordinatetransform.py index 1e9fb914342a..65201e5a984b 100644 --- a/tests/src/python/test_qgscoordinatetransform.py +++ b/tests/src/python/test_qgscoordinatetransform.py @@ -11,11 +11,14 @@ from qgis.core import ( + Qgis, QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsCoordinateTransformContext, QgsProject, QgsRectangle, + QgsPointXY, + QgsCsException ) import unittest from qgis.testing import start_app, QgisTestCase @@ -208,6 +211,22 @@ def test_has_vertical_component(self): ) self.assertTrue(transform.hasVerticalComponent()) + def test_cs_exception(self): + ct = QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:4326'), + QgsCoordinateReferenceSystem('EPSG:3857'), QgsProject.instance()) + point = QgsPointXY(-7603859, -7324441) + with self.assertRaises(QgsCsException) as e: + ct.transform(point) + self.assertEqual(str(e.exception), 'Forward transform (EPSG:4326 to EPSG:3857) of (-7603859.000000, -7324441.000000) Error: Invalid coordinate') + + # reverse transform + ct = QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:3857'), + QgsCoordinateReferenceSystem('EPSG:4326'), QgsProject.instance()) + point = QgsPointXY(-7603859, -7324441) + with self.assertRaises(QgsCsException) as e: + ct.transform(point, Qgis.TransformDirection.Reverse) + self.assertEqual(str(e.exception), 'Inverse transform (EPSG:4326 to EPSG:3857) of (-7603859.000000, -7324441.000000) Error: Invalid coordinate') + if __name__ == '__main__': unittest.main()