Skip to content
Permalink
Browse files

Catch exceptions in transform() expression function

(cherry-picked from 2a8333e)
  • Loading branch information
nyalldawson committed Sep 15, 2016
1 parent 60fcddf commit d6d3ad1cba228ef7c8a8b3b13ad1a6bdb5af2438
Showing with 13 additions and 2 deletions.
  1. +12 −2 src/core/qgsexpression.cpp
  2. +1 −0 tests/src/core/testqgsexpression.cpp
@@ -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>
@@ -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();
}

@@ -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" );

0 comments on commit d6d3ad1

Please sign in to comment.
You can’t perform that action at this time.