Skip to content

Commit

Permalink
Catch exceptions in transform() expression function
Browse files Browse the repository at this point in the history
(cherry-picked from 2a8333e)
  • Loading branch information
nyalldawson committed Sep 15, 2016
1 parent 60fcddf commit d6d3ad1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/qgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include "qgsexpressionprivate.h"
#include "qgsexpressionsorter.h"
#include "qgscrscache.h"
#include "qgsmessagelog.h"
#include "qgscsexception.h"

#if QT_VERSION < 0x050000
#include <qtextdocument.h>
Expand Down Expand Up @@ -3048,8 +3050,16 @@ static QVariant fcnTransformGeometry( const QVariantList& values, const QgsExpre
return QVariant::fromValue( fGeom );

QgsCoordinateTransform t( s, d );
if ( fGeom.transform( t ) == 0 )
return QVariant::fromValue( fGeom );
try
{
if ( fGeom.transform( t ) == 0 )
return QVariant::fromValue( fGeom );
}
catch ( QgsCsException &cse )
{
QgsMessageLog::logMessage( QString( "Transform error caught in transform() function: %1" ).arg( cse.what() ) );
return QVariant();
}
return QVariant();
}

Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "distance_to_vertex null" ) << "distance_to_vertex(NULL, 0)" << false << QVariant();
QTest::newRow( "distance_to_vertex point" ) << "distance_to_vertex(geom_from_wkt('POINT(1 2)'),0)" << false << QVariant( 0.0 );
QTest::newRow( "distance_to_vertex line" ) << "distance_to_vertex(geometry:=geom_from_wkt('LineString(0 0, 10 0, 10 10)'),vertex:=1)" << false << QVariant( 10.0 );
QTest::newRow( "transform invalid" ) << "transform(make_point(0,0),'EPSG:4326','EPSG:28356')" << false << QVariant();

// string functions
QTest::newRow( "lower" ) << "lower('HeLLo')" << false << QVariant( "hello" );
Expand Down

0 comments on commit d6d3ad1

Please sign in to comment.