Skip to content

Commit

Permalink
More consistent exception throwing in QgsCoordinateTransform::transfo…
Browse files Browse the repository at this point in the history
…rmBoundingBox

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)
  • Loading branch information
nyalldawson committed Nov 19, 2017
1 parent 957cf65 commit 705416c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/qgscoordinatetransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/src/core/testqgscoordinatetransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgsrectangle.h"
#include <QObject>
#include "qgstest.h"
#include "qgsexception.h"

class TestQgsCoordinateTransform: public QObject
{
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit 705416c

Please sign in to comment.