Skip to content
Permalink
Browse files

Resurrect select by attribute algorithm

  • Loading branch information
nyalldawson committed Jun 27, 2017
1 parent 4e93f8d commit 3a9a0efc333f97eaf736eafe500a6855228d262c
@@ -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
@@ -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
@@ -202,7 +202,6 @@ def getAlgs(self):
# ExtractByLocation(),
# SpatialJoin(),
# DeleteDuplicateGeometries(), TextToFloat(),
# SelectByAttribute(),
# GridLine(), Gridify(), HubDistancePoints(),
# HubDistanceLines(), HubLines(),
# GeometryConvert(), FieldsCalculator(),
@@ -266,6 +265,7 @@ def getAlgs(self):
RandomExtractWithinSubsets(),
RegularPoints(),
SaveSelectedFeatures(),
SelectByAttribute(),
SimplifyGeometries(),
Smooth(),
SpatialiteExecuteSQL(),
@@ -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):
@@ -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'
@@ -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()

@@ -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.
You can’t perform that action at this time.