Skip to content
Permalink
Browse files

[processing] Use faster expression request for ExtractByAttribute

  • Loading branch information
nyalldawson committed Nov 16, 2015
1 parent e15962e commit 48afc425dcc4404895c2054c6255047a7371acb4
Showing with 7 additions and 10 deletions.
  1. +7 −10 python/plugins/processing/algs/qgis/ExtractByAttribute.py
@@ -26,7 +26,7 @@
__revision__ = '$Format:%H$'

from PyQt4.QtCore import QVariant
from qgis.core import QgsExpression
from qgis.core import QgsExpression, QgsFeatureRequest
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
@@ -117,15 +117,12 @@ def processAlgorithm(self, progress):
self.tr('Unsupported field type "%s"' % fields[idx].typeName()))

expression = QgsExpression(expr)
expression.prepare(fields)

features = vector.features(layer)
if not expression.hasParserError():
req = QgsFeatureRequest(expression)
else:
raise GeoAlgorithmExecutionException(expression.parserErrorString())

count = len(features)
total = 100.0 / float(count)
for count, f in enumerate(features):
if expression.evaluate(f, fields):
writer.addFeature(f)
progress.setPercentage(int(count * total))
for f in layer.getFeatures(req):
writer.addFeature(f)

del writer

0 comments on commit 48afc42

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