|
26 | 26 | __revision__ = '$Format:%H$'
|
27 | 27 |
|
28 | 28 | from PyQt4.QtCore import QVariant
|
29 |
| -from qgis.core import QgsExpression |
| 29 | +from qgis.core import QgsExpression, QgsFeatureRequest |
30 | 30 | from processing.core.GeoAlgorithm import GeoAlgorithm
|
31 | 31 | from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
32 | 32 | from processing.core.parameters import ParameterVector
|
@@ -115,18 +115,12 @@ def processAlgorithm(self, progress):
|
115 | 115 | raise GeoAlgorithmExecutionException(
|
116 | 116 | self.tr('Unsupported field type "%s"' % fields[idx].typeName()))
|
117 | 117 |
|
118 |
| - expression = QgsExpression(expr) |
119 |
| - expression.prepare(fields) |
120 |
| - |
121 |
| - features = vector.features(layer) |
122 |
| - |
123 |
| - selected = [] |
124 |
| - count = len(features) |
125 |
| - total = 100.0 / float(count) |
126 |
| - for count, f in enumerate(features): |
127 |
| - if expression.evaluate(f, fields): |
128 |
| - selected.append(f.id()) |
129 |
| - progress.setPercentage(int(count * total)) |
| 118 | + qExp = QgsExpression(expr) |
| 119 | + if not qExp.hasParserError(): |
| 120 | + qReq = QgsFeatureRequest(qExp) |
| 121 | + else: |
| 122 | + raise GeoAlgorithmExecutionException(qExp.parserErrorString()) |
| 123 | + selected = [f.id() for f in layer.getFeatures(qReq)] |
130 | 124 |
|
131 | 125 | layer.setSelectedFeatures(selected)
|
132 | 126 | self.setOutputValue(self.OUTPUT, fileName)
|
0 commit comments