Skip to content

Commit

Permalink
[processing] Use faster expression request for ExtractByAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 16, 2015
1 parent e15962e commit 48afc42
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions python/plugins/processing/algs/qgis/ExtractByAttribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.