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
Expand Up @@ -26,7 +26,7 @@
__revision__ = '$Format:%H$' __revision__ = '$Format:%H$'


from PyQt4.QtCore import QVariant 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.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector 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())) self.tr('Unsupported field type "%s"' % fields[idx].typeName()))


expression = QgsExpression(expr) expression = QgsExpression(expr)
expression.prepare(fields) if not expression.hasParserError():

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


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


del writer del writer

0 comments on commit 48afc42

Please sign in to comment.