Skip to content

Commit

Permalink
Resurrect select by attribute algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 27, 2017
1 parent 4e93f8d commit 3a9a0ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -64,6 +64,7 @@
from .RandomExtractWithinSubsets import RandomExtractWithinSubsets
from .RegularPoints import RegularPoints
from .SaveSelectedFeatures import SaveSelectedFeatures
from .SelectByAttribute import SelectByAttribute
from .SimplifyGeometries import SimplifyGeometries
from .Smooth import Smooth
from .SpatialiteExecuteSQL import SpatialiteExecuteSQL
Expand Down Expand Up @@ -99,7 +100,6 @@
# from .SpatialJoin import SpatialJoin
# from .DeleteDuplicateGeometries import DeleteDuplicateGeometries
# from .TextToFloat import TextToFloat
# from .SelectByAttribute import SelectByAttribute
# from .GridLine import GridLine
# from .Gridify import Gridify
# from .HubDistancePoints import HubDistancePoints
Expand Down Expand Up @@ -202,7 +202,6 @@ def getAlgs(self):
# ExtractByLocation(),
# SpatialJoin(),
# DeleteDuplicateGeometries(), TextToFloat(),
# SelectByAttribute(),
# GridLine(), Gridify(), HubDistancePoints(),
# HubDistanceLines(), HubLines(),
# GeometryConvert(), FieldsCalculator(),
Expand Down Expand Up @@ -266,6 +265,7 @@ def getAlgs(self):
RandomExtractWithinSubsets(),
RegularPoints(),
SaveSelectedFeatures(),
SelectByAttribute(),
SimplifyGeometries(),
Smooth(),
SpatialiteExecuteSQL(),
Expand Down
40 changes: 20 additions & 20 deletions python/plugins/processing/algs/qgis/SelectByAttribute.py
Expand Up @@ -28,14 +28,14 @@
from qgis.core import (QgsApplication)
from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsExpression,
QgsProcessingUtils)
QgsProcessingUtils,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterField,
QgsProcessingParameterEnum,
QgsProcessingParameterString,
QgsProcessingOutputVectorLayer)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterTableField
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterString
from processing.core.outputs import OutputVector


class SelectByAttribute(QgisAlgorithm):
Expand Down Expand Up @@ -82,15 +82,15 @@ def __init__(self):
self.tr('does not contain')
]

self.addParameter(ParameterVector(self.INPUT,
self.tr('Input Layer')))
self.addParameter(ParameterTableField(self.FIELD,
self.tr('Selection attribute'), self.INPUT))
self.addParameter(ParameterSelection(self.OPERATOR,
self.tr('Operator'), self.i18n_operators))
self.addParameter(ParameterString(self.VALUE, self.tr('Value')))
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT, self.tr('Input layer')))

self.addOutput(OutputVector(self.OUTPUT, self.tr('Selected (attribute)'), True))
self.addParameter(QgsProcessingParameterField(self.FIELD,
self.tr('Selection attribute'), parentLayerParameterName=self.INPUT))
self.addParameter(QgsProcessingParameterEnum(self.OPERATOR,
self.tr('Operator'), self.i18n_operators))
self.addParameter(QgsProcessingParameterString(self.VALUE, self.tr('Value')))

self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Selected (attribute)')))

def name(self):
return 'selectbyattribute'
Expand All @@ -99,11 +99,11 @@ def displayName(self):
return self.tr('Select by attribute')

def processAlgorithm(self, parameters, context, feedback):
fileName = self.getParameterValue(self.INPUT)
layer = QgsProcessingUtils.mapLayerFromString(fileName, context)
fieldName = self.getParameterValue(self.FIELD)
operator = self.OPERATORS[self.getParameterValue(self.OPERATOR)]
value = self.getParameterValue(self.VALUE)
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)

fieldName = self.parameterAsString(parameters, self.FIELD, context)
operator = self.OPERATORS[self.parameterAsEnum(parameters, self.OPERATOR, context)]
value = self.parameterAsString(parameters, self.VALUE, context)

fields = layer.fields()

Expand Down Expand Up @@ -135,4 +135,4 @@ def processAlgorithm(self, parameters, context, feedback):
raise GeoAlgorithmExecutionException(expression.parserErrorString())

layer.selectByExpression(expression_string)
self.setOutputValue(self.OUTPUT, fileName)
return {self.OUTPUT: parameters[self.INPUT]}

0 comments on commit 3a9a0ef

Please sign in to comment.