Skip to content
Permalink
Browse files

Port create attribute index alg to new api

  • Loading branch information
nyalldawson committed Jun 21, 2017
1 parent c685ec2 commit a9f97fc478d2c6f3da218057ebe78a721af94e82
@@ -28,12 +28,12 @@
from qgis.core import (QgsVectorDataProvider,
QgsFields,
QgsApplication,
QgsProcessingUtils)
QgsProcessingParameterVectorLayer,
QgsProcessingParameterField,
QgsProcessingParameterDefinition,
QgsProcessingOutputVectorLayer)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.parameters import ParameterTable
from processing.core.parameters import ParameterTableField
from processing.core.outputs import OutputVector


class CreateAttributeIndex(QgisAlgorithm):
@@ -53,12 +53,11 @@ def group(self):

def __init__(self):
super().__init__()
self.addParameter(ParameterTable(self.INPUT,
self.tr('Input Layer')))
self.addParameter(ParameterTableField(self.FIELD,
self.tr('Attribute to index'), self.INPUT))
self.addOutput(OutputVector(self.OUTPUT,
self.tr('Indexed layer'), True))
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
self.tr('Input Layer')))
self.addParameter(QgsProcessingParameterField(self.FIELD,
self.tr('Attribute to index'), None, self.INPUT))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Indexed layer')))

def name(self):
return 'createattributeindex'
@@ -67,9 +66,8 @@ def displayName(self):
return self.tr('Create attribute index')

def processAlgorithm(self, parameters, context, feedback):
file_name = self.getParameterValue(self.INPUT)
layer = QgsProcessingUtils.mapLayerFromString(file_name, context)
field = self.getParameterValue(self.FIELD)
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
field = self.parameterAsString(parameters, self.FIELD, context)
provider = layer.dataProvider()

field_index = layer.fields().lookupField(field)
@@ -84,4 +82,4 @@ def processAlgorithm(self, parameters, context, feedback):
feedback.pushInfo(self.tr("Layer's data provider does not support "
"creating attribute indexes"))

self.setOutputValue(self.OUTPUT, file_name)
return {self.OUTPUT: layer.id()}
@@ -168,7 +168,7 @@
# from .SnapGeometries import SnapGeometriesToLayer
# from .PoleOfInaccessibility import PoleOfInaccessibility
# from .RasterCalculator import RasterCalculator
# from .CreateAttributeIndex import CreateAttributeIndex
from .CreateAttributeIndex import CreateAttributeIndex
from .DropGeometry import DropGeometry
from .BasicStatistics import BasicStatisticsForField
# from .Heatmap import Heatmap
@@ -249,7 +249,7 @@ def getAlgs(self):
# RemoveNullGeometry(),
# ExtendLines(), ExtractSpecificNodes(),
# GeometryByExpression(), SnapGeometriesToLayer(),
# PoleOfInaccessibility(), CreateAttributeIndex(),
# PoleOfInaccessibility(),
#
# RasterCalculator(), Heatmap(), Orthogonalize(),
# ShortestPathPointToPoint(), ShortestPathPointToLayer(),
@@ -266,6 +266,7 @@ def getAlgs(self):
BoundingBox(),
CheckValidity(),
Clip(),
CreateAttributeIndex(),
DeleteColumn(),
DeleteHoles(),
DensifyGeometries(),
@@ -1303,7 +1303,7 @@ def create_wrapper_from_class(param, dialog, row=0, col=0):
wrapper = StringWidgetWrapper
elif param.type() == 'expression':
wrapper = ExpressionWidgetWrapper
elif param.type() == 'table':
elif param.type() == 'vector':
wrapper = TableWidgetWrapper
elif param.type() == 'field':
wrapper = TableFieldWidgetWrapper

0 comments on commit a9f97fc

Please sign in to comment.
You can’t perform that action at this time.