Skip to content

Commit 705416c

Browse files
committedNov 19, 2017
More consistent exception throwing in QgsCoordinateTransform::transformBoundingBox
Depending on the os and proj versions, we weren't always getting an exception when a bad bounding box transform was made. So now we explicitly check the result, and if everything was invalid then we also throw an exception. This makes the behavior consistent across different platforms, and fixes running the provider tests on non Travis platforms (highly likely also fixes various issues encountered while running QGIS)
1 parent 957cf65 commit 705416c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
 

‎src/core/qgscoordinatetransform.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ QgsRectangle QgsCoordinateTransform::transformBoundingBox( const QgsRectangle &r
426426
}
427427
}
428428

429+
if ( bb_rect.isNull() )
430+
{
431+
// something bad happened when reprojecting the filter rect... no finite points were left!
432+
throw QgsCsException( QObject::tr( "Could not transform bounding box to target CRS" ) );
433+
}
434+
429435
if ( handle180Crossover )
430436
{
431437
//subtract temporary addition of 360 degrees from longitudes

‎tests/src/core/testqgscoordinatetransform.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsrectangle.h"
2020
#include <QObject>
2121
#include "qgstest.h"
22+
#include "qgsexception.h"
2223

2324
class TestQgsCoordinateTransform: public QObject
2425
{
@@ -204,6 +205,20 @@ void TestQgsCoordinateTransform::transformBoundingBox()
204205
QGSCOMPARENEAR( resultRect.yMinimum(), expectedRect.yMinimum(), 0.001 );
205206
QGSCOMPARENEAR( resultRect.xMaximum(), expectedRect.xMaximum(), 0.001 );
206207
QGSCOMPARENEAR( resultRect.yMaximum(), expectedRect.yMaximum(), 0.001 );
208+
209+
// test transforming a bounding box, resulting in an invalid transform - exception must be thrown
210+
tr = QgsCoordinateTransform( QgsCoordinateReferenceSystem( 4326 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:28356" ) ) );
211+
QgsRectangle rect( -99999999999, 99999999999, -99999999998, 99999999998 );
212+
bool errorObtained = false;
213+
try
214+
{
215+
resultRect = tr.transformBoundingBox( rect );
216+
}
217+
catch ( QgsCsException & )
218+
{
219+
errorObtained = true;
220+
}
221+
QVERIFY( errorObtained );
207222
}
208223

209224
QGSTEST_MAIN( TestQgsCoordinateTransform )

0 commit comments

Comments
 (0)
Please sign in to comment.