Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revert "[FEATURE][expressions] implicit feature->geom conversion"
This reverts commit 7cab60b.

The conversion was unreliable, as it was not correctly determining
that the feature's geometry was required and consequently not
fetching it from the provider. This isn't trivial to fix, so
I'm reverting this feature before release.
  • Loading branch information
nyalldawson committed Jun 17, 2016
1 parent 6035f19 commit 9abb6c4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
11 changes: 1 addition & 10 deletions src/core/qgsexpression.cpp
Expand Up @@ -284,15 +284,6 @@ static QgsGeometry getGeometry( const QVariant& value, QgsExpression* parent )
{
if ( value.canConvert<QgsGeometry>() )
return value.value<QgsGeometry>();
else if ( value.canConvert<QgsFeature>() )
{
//try to grab geometry from feature
QgsFeature f = value.value<QgsFeature>();
if ( f.constGeometry() )
{
return *f.constGeometry();
}
}

parent->setEvalErrorString( "Cannot convert to QgsGeometry" );
return QgsGeometry();
Expand Down Expand Up @@ -1162,7 +1153,7 @@ static QVariant fcnWordwrap( const QVariantList& values, const QgsExpressionCont
static QVariant fcnLength( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
{
// two variants, one for geometry, one for string
if ( values.at( 0 ).canConvert<QgsGeometry>() || values.at( 0 ).canConvert<QgsFeature>() )
if ( values.at( 0 ).canConvert<QgsGeometry>() )
{
//geometry variant
QgsGeometry geom = getGeometry( values.at( 0 ), parent );
Expand Down
25 changes: 0 additions & 25 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -1566,31 +1566,6 @@ class TestQgsExpression: public QObject
QCOMPARE( out.toDouble(), result );
}

void implicit_feature_to_geometry()
{
// test implicit feature to geometry cast
QgsPolyline polyline;
polyline << QgsPoint( 0, 0 ) << QgsPoint( 10, 0 );
QgsFeature feat;
feat.setGeometry( QgsGeometry::fromPolyline( polyline ) );

QgsExpressionContext context;
context.setFeature( feat );
QgsExpression exp1( "length($currentfeature)" );
QVariant result = exp1.evaluate( &context );
QCOMPARE( result.toDouble(), 10. );

QgsExpression exp2( "x(end_point($currentfeature))" );
result = exp2.evaluate( &context );
QCOMPARE( result.toDouble(), 10. );

// feature without geometry
QgsFeature feat2;
context.setFeature( feat2 );
result = exp2.evaluate( &context );
QVERIFY( !result.isValid() );
}

void eval_geometry_calc()
{
QgsPolyline polyline, polygon_ring;
Expand Down

0 comments on commit 9abb6c4

Please sign in to comment.