diff --git a/src/core/qgscoordinatetransform.cpp b/src/core/qgscoordinatetransform.cpp index d07fc2953b1..fd08c905018 100644 --- a/src/core/qgscoordinatetransform.cpp +++ b/src/core/qgscoordinatetransform.cpp @@ -426,6 +426,12 @@ QgsRectangle QgsCoordinateTransform::transformBoundingBox( const QgsRectangle &r } } + if ( bb_rect.isNull() ) + { + // something bad happened when reprojecting the filter rect... no finite points were left! + throw QgsCsException( QObject::tr( "Could not transform bounding box to target CRS" ) ); + } + if ( handle180Crossover ) { //subtract temporary addition of 360 degrees from longitudes diff --git a/tests/src/core/testqgscoordinatetransform.cpp b/tests/src/core/testqgscoordinatetransform.cpp index b0e28bcee4f..b9d554b4230 100644 --- a/tests/src/core/testqgscoordinatetransform.cpp +++ b/tests/src/core/testqgscoordinatetransform.cpp @@ -19,6 +19,7 @@ #include "qgsrectangle.h" #include #include "qgstest.h" +#include "qgsexception.h" class TestQgsCoordinateTransform: public QObject { @@ -204,6 +205,20 @@ void TestQgsCoordinateTransform::transformBoundingBox() QGSCOMPARENEAR( resultRect.yMinimum(), expectedRect.yMinimum(), 0.001 ); QGSCOMPARENEAR( resultRect.xMaximum(), expectedRect.xMaximum(), 0.001 ); QGSCOMPARENEAR( resultRect.yMaximum(), expectedRect.yMaximum(), 0.001 ); + + // test transforming a bounding box, resulting in an invalid transform - exception must be thrown + tr = QgsCoordinateTransform( QgsCoordinateReferenceSystem( 4326 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:28356" ) ) ); + QgsRectangle rect( -99999999999, 99999999999, -99999999998, 99999999998 ); + bool errorObtained = false; + try + { + resultRect = tr.transformBoundingBox( rect ); + } + catch ( QgsCsException & ) + { + errorObtained = true; + } + QVERIFY( errorObtained ); } QGSTEST_MAIN( TestQgsCoordinateTransform )