Skip to content
Permalink
Browse files

Catch exceptions in transform() expression function

  • Loading branch information
nyalldawson committed Sep 15, 2016
1 parent a1e62a8 commit 2a8333ef6be003b8c391a72dbed033a33373d677
Showing with 13 additions and 2 deletions.
  1. +12 −2 src/core/qgsexpression.cpp
  2. +1 −0 tests/src/core/testqgsexpression.cpp
@@ -52,6 +52,8 @@
#include "qgsexpressionprivate.h"
#include "qgsexpressionsorter.h"
#include "qgsmaptopixelgeometrysimplifier.h"
#include "qgsmessagelog.h"
#include "qgscsexception.h"

#if QT_VERSION < 0x050000
#include <qtextdocument.h>
@@ -3023,8 +3025,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();
}

@@ -810,6 +810,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "smooth null" ) << "smooth(NULL,5)" << false << QVariant();
QTest::newRow( "smooth point" ) << "geom_to_wkt(smooth(geom_from_wkt('POINT(1 2)'),10))" << false << QVariant( "Point (1 2)" );
QTest::newRow( "smooth line" ) << "geom_to_wkt(smooth(geometry:=geom_from_wkt('LineString(0 0, 5 0, 5 5)'),iterations:=1,offset:=0.2,min_length:=-1,max_angle:=180))" << false << QVariant( "LineString (0 0, 4 0, 5 1, 5 5)" );
QTest::newRow( "transform invalid" ) << "transform(make_point(0,0),'EPSG:4326','EPSG:28356')" << false << QVariant();

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Apr 29, 2017

Member

Apparently this transformation succeeds on mac

e = QgsExpression("transform(make_point(0,0),'EPSG:4326','EPSG:28356')")
e.evaluate().exportToWkt()
'Point (-2623105.69023970561102033 29995929.88587754219770432)'

Do you have an idea, what's going on there? Do we need to take different CRS'es to perform this test or is there something else broken and this transformation is really meant to fail and it's bad that it succeeds on mac?

This is the reason for the blacklisted testqgsgeometry on mac.

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Apr 29, 2017

Author Collaborator

@m-kuhn it's quite odd that it's succeeds... It's clearly invalid inputs for 4326.

Does using dbl_max instead of these values help?

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Apr 29, 2017

Member

Is it invalid? 0, 0 seems to be inside the bounds of -180.0000, -90.0000, 180.0000, 90.0000.
Let's see how #4448 does

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Apr 29, 2017

Author Collaborator

Whoops - misread that line. It's outside the bounds of 28356, not 4326


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

0 comments on commit 2a8333e

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