Skip to content
Permalink
Browse files

Use FilterExpression request for get_feature expression function

Makes the function magnitudes faster for Postgres layers where
the expression is compiled and can take advantage of Postgres
indexes on the layer.
  • Loading branch information
nyalldawson committed Nov 5, 2015
1 parent 6772ffb commit e0fc9a9c722a5aaf2828497f6610ac82b6776676
Showing with 5 additions and 7 deletions.
  1. +5 −7 src/core/qgsexpression.cpp
@@ -2033,20 +2033,18 @@ static QVariant fcnGetFeature( const QVariantList& values, const QgsExpressionCo

const QVariant& attVal = values.at( 2 );
QgsFeatureRequest req;
req.setFilterExpression( QString( "%1=%2" ).arg( QgsExpression::quotedColumnRef( attribute ),
QgsExpression::quotedString( attVal.toString() ) ) );
if ( !parent->needsGeometry() )
{
req.setFlags( QgsFeatureRequest::NoGeometry );
}
QgsFeatureIterator fIt = vl->getFeatures( req );

QgsFeature fet;
while ( fIt.nextFeature( fet ) )
{
if ( fet.attribute( attributeId ) == attVal )
{
return QVariant::fromValue( fet );
}
}
if ( fIt.nextFeature( fet ) )
return QVariant::fromValue( fet );

return QVariant();
}

0 comments on commit e0fc9a9

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