@@ -865,6 +865,22 @@ class TestQgsExpression: public QObject
865
865
}
866
866
}
867
867
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
+
868
884
void eval_rand ()
869
885
{
870
886
QgsExpression exp1 ( " rand(1,10)" );
@@ -1234,6 +1250,7 @@ class TestQgsExpression: public QObject
1234
1250
QTest::addColumn<QString>( " string" );
1235
1251
QTest::addColumn<void *>( " geomptr" );
1236
1252
QTest::addColumn<bool >( " evalError" );
1253
+ QTest::addColumn<bool >( " needsGeom" );
1237
1254
1238
1255
QgsPoint point ( 123 , 456 );
1239
1256
QgsPolyline line;
@@ -1245,10 +1262,10 @@ class TestQgsExpression: public QObject
1245
1262
QgsPolygon polygon;
1246
1263
polygon << polygon_ring;
1247
1264
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 ;
1252
1269
1253
1270
QgsCoordinateReferenceSystem s;
1254
1271
s.createFromOgcWmsCrs ( " EPSG:4326" );
@@ -1263,8 +1280,8 @@ class TestQgsExpression: public QObject
1263
1280
1264
1281
QgsGeometry* oLine = QgsGeometry::fromPolyline ( line );
1265
1282
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 ;
1268
1285
delete oLine;
1269
1286
delete oPolygon;
1270
1287
}
@@ -1274,6 +1291,7 @@ class TestQgsExpression: public QObject
1274
1291
QFETCH ( QString, string );
1275
1292
QFETCH ( void *, geomptr );
1276
1293
QFETCH ( bool , evalError );
1294
+ QFETCH ( bool , needsGeom );
1277
1295
1278
1296
QgsGeometry* geom = ( QgsGeometry* ) geomptr;
1279
1297
@@ -1282,7 +1300,7 @@ class TestQgsExpression: public QObject
1282
1300
1283
1301
QgsExpression exp ( string );
1284
1302
QCOMPARE ( exp.hasParserError (), false );
1285
- QCOMPARE ( exp.needsGeometry (), false );
1303
+ QCOMPARE ( exp.needsGeometry (), needsGeom );
1286
1304
1287
1305
// deprecated method
1288
1306
Q_NOWARN_DEPRECATED_PUSH
0 commit comments