Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix expression get_feature function was not fetching feature's
geometry

Fix #13695
  • Loading branch information
nyalldawson committed Nov 2, 2015
1 parent 353c0db commit c445ac1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsexpression.cpp
Expand Up @@ -2332,7 +2332,7 @@ const QList<QgsExpression::Function*>& QgsExpression::Functions()
<< new StaticFunction( "combine", 2, fcnCombine, "GeometryGroup" )
<< new StaticFunction( "union", 2, fcnCombine, "GeometryGroup" )
<< new StaticFunction( "geom_to_wkt", -1, fcnGeomToWKT, "GeometryGroup", QString(), false, QStringList(), false, QStringList() << "geomToWKT" )
<< new StaticFunction( "geometry", 1, fcnGetGeometry, "GeometryGroup" )
<< new StaticFunction( "geometry", 1, fcnGetGeometry, "GeometryGroup", QString(), true )
<< new StaticFunction( "transform", 3, fcnTransformGeometry, "GeometryGroup" )
<< new StaticFunction( "$rownum", 0, fcnRowNumber, "deprecated" )
<< new StaticFunction( "$id", 0, fcnFeatureId, "Record" )
Expand Down
32 changes: 25 additions & 7 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -865,6 +865,22 @@ class TestQgsExpression: public QObject
}
}

void get_feature_geometry()
{
//test that get_feature fetches feature's geometry
QgsExpression exp( QString( "x(geometry(get_feature('%1','heading',340)))" ).arg( mPointsLayer->id() ) );
QCOMPARE( exp.hasParserError(), false );
if ( exp.hasParserError() )
qDebug() << exp.parserErrorString();

QVariant res = exp.evaluate();
if ( exp.hasEvalError() )
qDebug() << exp.evalErrorString();

QCOMPARE( exp.hasEvalError(), false );
QVERIFY( qgsDoubleNear( res.toDouble(), -85.65217, 0.00001 ) );
}

void eval_rand()
{
QgsExpression exp1( "rand(1,10)" );
Expand Down Expand Up @@ -1234,6 +1250,7 @@ class TestQgsExpression: public QObject
QTest::addColumn<QString>( "string" );
QTest::addColumn<void*>( "geomptr" );
QTest::addColumn<bool>( "evalError" );
QTest::addColumn<bool>( "needsGeom" );

QgsPoint point( 123, 456 );
QgsPolyline line;
Expand All @@ -1245,10 +1262,10 @@ class TestQgsExpression: public QObject
QgsPolygon polygon;
polygon << polygon_ring;

QTest::newRow( "geometry Point" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPoint( point ) << false;
QTest::newRow( "geometry Line" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolyline( line ) << false;
QTest::newRow( "geometry Polyline" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolyline( polyline ) << false;
QTest::newRow( "geometry Polygon" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolygon( polygon ) << false;
QTest::newRow( "geometry Point" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPoint( point ) << false << true;
QTest::newRow( "geometry Line" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolyline( line ) << false << true;
QTest::newRow( "geometry Polyline" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolyline( polyline ) << false << true;
QTest::newRow( "geometry Polygon" ) << "geometry( $currentfeature )" << ( void* ) QgsGeometry::fromPolygon( polygon ) << false << true;

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

QgsGeometry* oLine = QgsGeometry::fromPolyline( line );
QgsGeometry* oPolygon = QgsGeometry::fromPolygon( polygon );
QTest::newRow( "transform Line" ) << "transform( geomFromWKT('" + oLine->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tLine << false;
QTest::newRow( "transform Polygon" ) << "transform( geomFromWKT('" + oPolygon->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tPolygon << false;
QTest::newRow( "transform Line" ) << "transform( geomFromWKT('" + oLine->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tLine << false << false;
QTest::newRow( "transform Polygon" ) << "transform( geomFromWKT('" + oPolygon->exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << ( void* ) tPolygon << false << false;
delete oLine;
delete oPolygon;
}
Expand All @@ -1274,6 +1291,7 @@ class TestQgsExpression: public QObject
QFETCH( QString, string );
QFETCH( void*, geomptr );
QFETCH( bool, evalError );
QFETCH( bool, needsGeom );

QgsGeometry* geom = ( QgsGeometry* ) geomptr;

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

QgsExpression exp( string );
QCOMPARE( exp.hasParserError(), false );
QCOMPARE( exp.needsGeometry(), false );
QCOMPARE( exp.needsGeometry(), needsGeom );

//deprecated method
Q_NOWARN_DEPRECATED_PUSH
Expand Down

0 comments on commit c445ac1

Please sign in to comment.