mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Port create attribute index alg to new api
This commit is contained in:
parent
c685ec2b30
commit
a9f97fc478
@ -28,12 +28,12 @@ __revision__ = '$Format:%H$'
|
||||
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 @@ class CreateAttributeIndex(QgisAlgorithm):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.addParameter(ParameterTable(self.INPUT,
|
||||
self.addParameter(QgsProcessingParameterVectorLayer(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(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 @@ class CreateAttributeIndex(QgisAlgorithm):
|
||||
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 @@ class CreateAttributeIndex(QgisAlgorithm):
|
||||
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 .Aspect import Aspect
|
||||
# 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 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
# RemoveNullGeometry(),
|
||||
# ExtendLines(), ExtractSpecificNodes(),
|
||||
# GeometryByExpression(), SnapGeometriesToLayer(),
|
||||
# PoleOfInaccessibility(), CreateAttributeIndex(),
|
||||
# PoleOfInaccessibility(),
|
||||
#
|
||||
# RasterCalculator(), Heatmap(), Orthogonalize(),
|
||||
# ShortestPathPointToPoint(), ShortestPathPointToLayer(),
|
||||
@ -266,6 +266,7 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
BoundingBox(),
|
||||
CheckValidity(),
|
||||
Clip(),
|
||||
CreateAttributeIndex(),
|
||||
DeleteColumn(),
|
||||
DeleteHoles(),
|
||||
DensifyGeometries(),
|
||||
|
@ -1303,7 +1303,7 @@ class WidgetWrapperFactory:
|
||||
wrapper = StringWidgetWrapper
|
||||
elif param.type() == 'expression':
|
||||
wrapper = ExpressionWidgetWrapper
|
||||
elif param.type() == 'table':
|
||||
elif param.type() == 'vector':
|
||||
wrapper = TableWidgetWrapper
|
||||
elif param.type() == 'field':
|
||||
wrapper = TableFieldWidgetWrapper
|
||||
|
Loading…
x
Reference in New Issue
Block a user