Skip to content
Permalink
Browse files

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 9abb6c43f285719de42b58034cddab4ee3f4a794
Showing with 1 addition and 35 deletions.
  1. +1 −10 src/core/qgsexpression.cpp
  2. +0 −25 tests/src/core/testqgsexpression.cpp
@@ -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();
@@ -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 );
@@ -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;

0 comments on commit 9abb6c4

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