Skip to content

Commit ae82985

Browse files
committed
Restore select by expression algorithm
1 parent f98bcb2 commit ae82985

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
from .RegularPoints import RegularPoints
6666
from .SaveSelectedFeatures import SaveSelectedFeatures
6767
from .SelectByAttribute import SelectByAttribute
68+
from .SelectByExpression import SelectByExpression
6869
from .SimplifyGeometries import SimplifyGeometries
6970
from .Smooth import Smooth
7071
from .SpatialiteExecuteSQL import SpatialiteExecuteSQL
@@ -128,7 +129,6 @@
128129
# from .PointsToPaths import PointsToPaths
129130
# from .SetVectorStyle import SetVectorStyle
130131
# from .SetRasterStyle import SetRasterStyle
131-
# from .SelectByExpression import SelectByExpression
132132
# from .SelectByAttributeSum import SelectByAttributeSum
133133
# from .HypsometricCurves import HypsometricCurves
134134
# from .SplitWithLines import SplitWithLines
@@ -216,7 +216,7 @@ def getAlgs(self):
216216
# RandomPointsPolygonsVariable(),
217217
# RandomPointsAlongLines(), PointsToPaths(),
218218
# SetVectorStyle(), SetRasterStyle(),
219-
# SelectByExpression(), HypsometricCurves(),
219+
# HypsometricCurves(),
220220
# SplitWithLines(), CreateConstantRaster(),
221221
# FieldsMapper(), SelectByAttributeSum(), Datasources2Vrt(),
222222
# OrientedMinimumBoundingBox(),
@@ -266,6 +266,7 @@ def getAlgs(self):
266266
RegularPoints(),
267267
SaveSelectedFeatures(),
268268
SelectByAttribute(),
269+
SelectByExpression(),
269270
SimplifyGeometries(),
270271
Smooth(),
271272
SpatialiteExecuteSQL(),

python/plugins/processing/algs/qgis/SelectByExpression.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,21 @@
2424

2525
__revision__ = '$Format:%H$'
2626

27-
from qgis.core import (QgsApplication,
28-
QgsExpression,
27+
from qgis.core import (QgsExpression,
2928
QgsVectorLayer,
30-
QgsProcessingUtils)
29+
QgsProcessingParameterVectorLayer,
30+
QgsProcessingParameterExpression,
31+
QgsProcessingParameterEnum,
32+
QgsProcessingOutputVectorLayer)
3133
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
32-
from processing.core.parameters import ParameterVector
33-
from processing.core.parameters import ParameterSelection
34-
from processing.core.outputs import OutputVector
3534
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
36-
from processing.core.parameters import ParameterExpression
3735

3836

3937
class SelectByExpression(QgisAlgorithm):
4038

41-
LAYERNAME = 'LAYERNAME'
39+
INPUT = 'INPUT'
4240
EXPRESSION = 'EXPRESSION'
43-
RESULT = 'RESULT'
41+
OUTPUT = 'OUTPUT'
4442
METHOD = 'METHOD'
4543

4644
def group(self):
@@ -53,13 +51,14 @@ def __init__(self):
5351
self.tr('removing from current selection'),
5452
self.tr('selecting within current selection')]
5553

56-
self.addParameter(ParameterVector(self.LAYERNAME,
57-
self.tr('Input Layer')))
58-
self.addParameter(ParameterExpression(self.EXPRESSION,
59-
self.tr("Expression"), parent_layer=self.LAYERNAME))
60-
self.addParameter(ParameterSelection(self.METHOD,
61-
self.tr('Modify current selection by'), self.methods, 0))
62-
self.addOutput(OutputVector(self.RESULT, self.tr('Selected (expression)'), True))
54+
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT, self.tr('Input layer')))
55+
56+
self.addParameter(QgsProcessingParameterExpression(self.EXPRESSION,
57+
self.tr('Expression'), parentLayerParameterName=self.INPUT))
58+
self.addParameter(QgsProcessingParameterEnum(self.METHOD,
59+
self.tr('Modify current selection by'), self.methods, 0))
60+
61+
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Selected (attribute)')))
6362

6463
def name(self):
6564
return 'selectbyexpression'
@@ -68,9 +67,9 @@ def displayName(self):
6867
return self.tr('Select by expression')
6968

7069
def processAlgorithm(self, parameters, context, feedback):
71-
filename = self.getParameterValue(self.LAYERNAME)
72-
layer = QgsProcessingUtils.mapLayerFromString(filename, context)
73-
method = self.getParameterValue(self.METHOD)
70+
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
71+
72+
method = self.parameterAsEnum(parameters, self.METHOD, context)
7473

7574
if method == 0:
7675
behavior = QgsVectorLayer.SetSelection
@@ -81,10 +80,10 @@ def processAlgorithm(self, parameters, context, feedback):
8180
elif method == 3:
8281
behavior = QgsVectorLayer.IntersectSelection
8382

84-
expression = self.getParameterValue(self.EXPRESSION)
83+
expression = self.parameterAsString(parameters, self.EXPRESSION, context)
8584
qExp = QgsExpression(expression)
8685
if qExp.hasParserError():
8786
raise GeoAlgorithmExecutionException(qExp.parserErrorString())
8887

8988
layer.selectByExpression(expression, behavior)
90-
self.setOutputValue(self.RESULT, filename)
89+
return {self.OUTPUT: parameters[self.INPUT]}

0 commit comments

Comments
 (0)