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,
|
from qgis.core import (QgsVectorDataProvider,
|
||||||
QgsFields,
|
QgsFields,
|
||||||
QgsApplication,
|
QgsApplication,
|
||||||
QgsProcessingUtils)
|
QgsProcessingParameterVectorLayer,
|
||||||
|
QgsProcessingParameterField,
|
||||||
|
QgsProcessingParameterDefinition,
|
||||||
|
QgsProcessingOutputVectorLayer)
|
||||||
|
|
||||||
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
|
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):
|
class CreateAttributeIndex(QgisAlgorithm):
|
||||||
@ -53,12 +53,11 @@ class CreateAttributeIndex(QgisAlgorithm):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.addParameter(ParameterTable(self.INPUT,
|
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
|
||||||
self.tr('Input Layer')))
|
self.tr('Input Layer')))
|
||||||
self.addParameter(ParameterTableField(self.FIELD,
|
self.addParameter(QgsProcessingParameterField(self.FIELD,
|
||||||
self.tr('Attribute to index'), self.INPUT))
|
self.tr('Attribute to index'), None, self.INPUT))
|
||||||
self.addOutput(OutputVector(self.OUTPUT,
|
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Indexed layer')))
|
||||||
self.tr('Indexed layer'), True))
|
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
return 'createattributeindex'
|
return 'createattributeindex'
|
||||||
@ -67,9 +66,8 @@ class CreateAttributeIndex(QgisAlgorithm):
|
|||||||
return self.tr('Create attribute index')
|
return self.tr('Create attribute index')
|
||||||
|
|
||||||
def processAlgorithm(self, parameters, context, feedback):
|
def processAlgorithm(self, parameters, context, feedback):
|
||||||
file_name = self.getParameterValue(self.INPUT)
|
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
|
||||||
layer = QgsProcessingUtils.mapLayerFromString(file_name, context)
|
field = self.parameterAsString(parameters, self.FIELD, context)
|
||||||
field = self.getParameterValue(self.FIELD)
|
|
||||||
provider = layer.dataProvider()
|
provider = layer.dataProvider()
|
||||||
|
|
||||||
field_index = layer.fields().lookupField(field)
|
field_index = layer.fields().lookupField(field)
|
||||||
@ -84,4 +82,4 @@ class CreateAttributeIndex(QgisAlgorithm):
|
|||||||
feedback.pushInfo(self.tr("Layer's data provider does not support "
|
feedback.pushInfo(self.tr("Layer's data provider does not support "
|
||||||
"creating attribute indexes"))
|
"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 .SnapGeometries import SnapGeometriesToLayer
|
||||||
# from .PoleOfInaccessibility import PoleOfInaccessibility
|
# from .PoleOfInaccessibility import PoleOfInaccessibility
|
||||||
# from .RasterCalculator import RasterCalculator
|
# from .RasterCalculator import RasterCalculator
|
||||||
# from .CreateAttributeIndex import CreateAttributeIndex
|
from .CreateAttributeIndex import CreateAttributeIndex
|
||||||
from .DropGeometry import DropGeometry
|
from .DropGeometry import DropGeometry
|
||||||
from .BasicStatistics import BasicStatisticsForField
|
from .BasicStatistics import BasicStatisticsForField
|
||||||
# from .Heatmap import Heatmap
|
# from .Heatmap import Heatmap
|
||||||
@ -249,7 +249,7 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
|||||||
# RemoveNullGeometry(),
|
# RemoveNullGeometry(),
|
||||||
# ExtendLines(), ExtractSpecificNodes(),
|
# ExtendLines(), ExtractSpecificNodes(),
|
||||||
# GeometryByExpression(), SnapGeometriesToLayer(),
|
# GeometryByExpression(), SnapGeometriesToLayer(),
|
||||||
# PoleOfInaccessibility(), CreateAttributeIndex(),
|
# PoleOfInaccessibility(),
|
||||||
#
|
#
|
||||||
# RasterCalculator(), Heatmap(), Orthogonalize(),
|
# RasterCalculator(), Heatmap(), Orthogonalize(),
|
||||||
# ShortestPathPointToPoint(), ShortestPathPointToLayer(),
|
# ShortestPathPointToPoint(), ShortestPathPointToLayer(),
|
||||||
@ -266,6 +266,7 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
|||||||
BoundingBox(),
|
BoundingBox(),
|
||||||
CheckValidity(),
|
CheckValidity(),
|
||||||
Clip(),
|
Clip(),
|
||||||
|
CreateAttributeIndex(),
|
||||||
DeleteColumn(),
|
DeleteColumn(),
|
||||||
DeleteHoles(),
|
DeleteHoles(),
|
||||||
DensifyGeometries(),
|
DensifyGeometries(),
|
||||||
|
@ -1303,7 +1303,7 @@ class WidgetWrapperFactory:
|
|||||||
wrapper = StringWidgetWrapper
|
wrapper = StringWidgetWrapper
|
||||||
elif param.type() == 'expression':
|
elif param.type() == 'expression':
|
||||||
wrapper = ExpressionWidgetWrapper
|
wrapper = ExpressionWidgetWrapper
|
||||||
elif param.type() == 'table':
|
elif param.type() == 'vector':
|
||||||
wrapper = TableWidgetWrapper
|
wrapper = TableWidgetWrapper
|
||||||
elif param.type() == 'field':
|
elif param.type() == 'field':
|
||||||
wrapper = TableFieldWidgetWrapper
|
wrapper = TableFieldWidgetWrapper
|
||||||
|
Loading…
x
Reference in New Issue
Block a user