Skip to content

Commit

Permalink
Use FilterExpression request for get_feature expression function
Browse files Browse the repository at this point in the history
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 e0fc9a9
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/core/qgsexpression.cpp
Expand Up @@ -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();
}

Expand Down

0 comments on commit e0fc9a9

Please sign in to comment.