Skip to content

Commit c445ac1

Browse files
committedNov 2, 2015
Fix expression get_feature function was not fetching feature's
geometry Fix #13695
1 parent 353c0db commit c445ac1

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed
 

‎src/core/qgsexpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,7 @@ const QList<QgsExpression::Function*>& QgsExpression::Functions()
23322332
<< new StaticFunction( "combine", 2, fcnCombine, "GeometryGroup" )
23332333
<< new StaticFunction( "union", 2, fcnCombine, "GeometryGroup" )
23342334
<< new StaticFunction( "geom_to_wkt", -1, fcnGeomToWKT, "GeometryGroup", QString(), false, QStringList(), false, QStringList() << "geomToWKT" )
2335-
<< new StaticFunction( "geometry", 1, fcnGetGeometry, "GeometryGroup" )
2335+
<< new StaticFunction( "geometry", 1, fcnGetGeometry, "GeometryGroup", QString(), true )
23362336
<< new StaticFunction( "transform", 3, fcnTransformGeometry, "GeometryGroup" )
23372337
<< new StaticFunction( "$rownum", 0, fcnRowNumber, "deprecated" )
23382338
<< new StaticFunction( "$id", 0, fcnFeatureId, "Record" )

‎tests/src/core/testqgsexpression.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,22 @@ class TestQgsExpression: public QObject
865865
}
866866
}
867867

868+
void get_feature_geometry()
869+
{
870+
//test that get_feature fetches feature's geometry
871+
QgsExpression exp( QString( "x(geometry(get_feature('%1','heading',340)))" ).arg( mPointsLayer->id() ) );
872+
QCOMPARE( exp.hasParserError(), false );
873+
if ( exp.hasParserError() )
874+
qDebug() << exp.parserErrorString();
875+
876+
QVariant res = exp.evaluate();
877+
if ( exp.hasEvalError() )
878+
qDebug() << exp.evalErrorString();
879+
880+
QCOMPARE( exp.hasEvalError(), false );
881+
QVERIFY( qgsDoubleNear( res.toDouble(), -85.65217, 0.00001 ) );
882+
}
883+
868884
void eval_rand()
869885
{
870886
QgsExpression exp1( "rand(1,10)" );
@@ -1234,6 +1250,7 @@ class TestQgsExpression: public QObject
12341250
QTest::addColumn<QString>( "string" );
12351251
QTest::addColumn<void*>( "geomptr" );
12361252
QTest::addColumn<bool>( "evalError" );
1253+
QTest::addColumn<bool>( "needsGeom" );
12371254

12381255
QgsPoint point( 123, 456 );
12391256
QgsPolyline line;
@@ -1245,10 +1262,10 @@ class TestQgsExpression: public QObject
12451262
QgsPolygon polygon;
12461263
polygon << polygon_ring;
12471264

1248-
QTest::newRow( "geometry Point" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPoint( point ) << false;
1249-
QTest::newRow( "geometry Line" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolyline( line ) << false;
1250-
QTest::newRow( "geometry Polyline" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolyline( polyline ) << false;
1251-
QTest::newRow( "geometry Polygon" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolygon( polygon ) << false;
1265+
QTest::newRow( "geometry Point" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPoint( point ) << false << true;
1266+
QTest::newRow( "geometry Line" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolyline( line ) << false << true;
1267+
QTest::newRow( "geometry Polyline" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolyline( polyline ) << false << true;
1268+
QTest::newRow( "geometry Polygon" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolygon( polygon ) << false << true;
12521269

12531270
QgsCoordinateReferenceSystem s;
12541271
s.createFromOgcWmsCrs( "EPSG:4326" );
@@ -1263,8 +1280,8 @@ class TestQgsExpression: public QObject
12631280

12641281
QgsGeometry* oLine = QgsGeometry::fromPolyline( line );
12651282
QgsGeometry* oPolygon = QgsGeometry::fromPolygon( polygon );
1266-
QTest::newRow( "transform Line" ) << "transform( geomFromWKT('" + oLine->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tLine << false;
1267-
QTest::newRow( "transform Polygon" ) << "transform( geomFromWKT('" + oPolygon->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tPolygon << false;
1283+
QTest::newRow( "transform Line" ) << "transform( geomFromWKT('" + oLine->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tLine << false << false;
1284+
QTest::newRow( "transform Polygon" ) << "transform( geomFromWKT('" + oPolygon->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tPolygon << false << false;
12681285
delete oLine;
12691286
delete oPolygon;
12701287
}
@@ -1274,6 +1291,7 @@ class TestQgsExpression: public QObject
12741291
QFETCH( QString, string );
12751292
QFETCH( void*, geomptr );
12761293
QFETCH( bool, evalError );
1294+
QFETCH( bool, needsGeom );
12771295

12781296
QgsGeometry* geom = ( QgsGeometry* ) geomptr;
12791297

@@ -1282,7 +1300,7 @@ class TestQgsExpression: public QObject
12821300

12831301
QgsExpression exp( string );
12841302
QCOMPARE( exp.hasParserError(), false );
1285-
QCOMPARE( exp.needsGeometry(), false );
1303+
QCOMPARE( exp.needsGeometry(), needsGeom );
12861304

12871305
//deprecated method
12881306
Q_NOWARN_DEPRECATED_PUSH

0 commit comments

Comments
 (0)
Please sign in to comment.