Skip to content

Commit 9abb6c4

Browse files
committed
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.
1 parent 6035f19 commit 9abb6c4

File tree

2 files changed

+1
-35
lines changed

2 files changed

+1
-35
lines changed

src/core/qgsexpression.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,6 @@ static QgsGeometry getGeometry( const QVariant& value, QgsExpression* parent )
284284
{
285285
if ( value.canConvert<QgsGeometry>() )
286286
return value.value<QgsGeometry>();
287-
else if ( value.canConvert<QgsFeature>() )
288-
{
289-
//try to grab geometry from feature
290-
QgsFeature f = value.value<QgsFeature>();
291-
if ( f.constGeometry() )
292-
{
293-
return *f.constGeometry();
294-
}
295-
}
296287

297288
parent->setEvalErrorString( "Cannot convert to QgsGeometry" );
298289
return QgsGeometry();
@@ -1162,7 +1153,7 @@ static QVariant fcnWordwrap( const QVariantList& values, const QgsExpressionCont
11621153
static QVariant fcnLength( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
11631154
{
11641155
// two variants, one for geometry, one for string
1165-
if ( values.at( 0 ).canConvert<QgsGeometry>() || values.at( 0 ).canConvert<QgsFeature>() )
1156+
if ( values.at( 0 ).canConvert<QgsGeometry>() )
11661157
{
11671158
//geometry variant
11681159
QgsGeometry geom = getGeometry( values.at( 0 ), parent );

tests/src/core/testqgsexpression.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,31 +1566,6 @@ class TestQgsExpression: public QObject
15661566
QCOMPARE( out.toDouble(), result );
15671567
}
15681568

1569-
void implicit_feature_to_geometry()
1570-
{
1571-
// test implicit feature to geometry cast
1572-
QgsPolyline polyline;
1573-
polyline << QgsPoint( 0, 0 ) << QgsPoint( 10, 0 );
1574-
QgsFeature feat;
1575-
feat.setGeometry( QgsGeometry::fromPolyline( polyline ) );
1576-
1577-
QgsExpressionContext context;
1578-
context.setFeature( feat );
1579-
QgsExpression exp1( "length($currentfeature)" );
1580-
QVariant result = exp1.evaluate( &context );
1581-
QCOMPARE( result.toDouble(), 10. );
1582-
1583-
QgsExpression exp2( "x(end_point($currentfeature))" );
1584-
result = exp2.evaluate( &context );
1585-
QCOMPARE( result.toDouble(), 10. );
1586-
1587-
// feature without geometry
1588-
QgsFeature feat2;
1589-
context.setFeature( feat2 );
1590-
result = exp2.evaluate( &context );
1591-
QVERIFY( !result.isValid() );
1592-
}
1593-
15941569
void eval_geometry_calc()
15951570
{
15961571
QgsPolyline polyline, polygon_ring;

0 commit comments

Comments
 (0)