Skip to content
Snippets Groups Projects
Commit baebd86c authored by Alexian Masson's avatar Alexian Masson
Browse files

Add RepairProfilesAlgorithm

parent 7d4a0477
No related branches found
No related tags found
1 merge request!75Gsedfqgis 118 create dedicated algo
from qgis.core import (
QgsProcessing,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputLayerDefinition
)
from PreCourlis import processing
from PreCourlis.processing.precourlis_algorithm import PreCourlisAlgorithm
class RepairProfilesAlgorithm(PreCourlisAlgorithm):
INPUT = "INPUT"
OUTPUT = "OUTPUT"
def initAlgorithm(self, config=None):
self.addParameter(
QgsProcessingParameterVectorLayer(
self.INPUT,
self.tr("Input"),
types=[QgsProcessing.TypeVectorLine],
defaultValue=None,
)
)
self.addParameter(
QgsProcessingParameterFeatureSink(
self.OUTPUT,
self.tr("Output"),
type=QgsProcessing.TypeVectorLine,
createByDefault=True,
defaultValue=None,
)
)
def processAlgorithm(self, parameters, context, model_feedback):
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
output = QgsProcessingOutputLayerDefinition(parameters[self.OUTPUT])
output.destinationName = self.tr("Interpolated")
TOPO_BAT_EXPR = "'B' || replace(rpad('', num_points($geometry) - 1, ','), ',', ',B')"
processing.run(
"native:refactorfields",
{
"INPUT": layer,
"FIELDS_MAPPING": [
{
"expression": '"sec_id"',
"length": 0,
"name": "sec_id",
"precision": 0,
"type": 2,
},
{
"expression": '"sec_name"',
"length": 0,
"name": "sec_name",
"precision": 0,
"type": 10,
},
{
"expression": '"abs_long"',
"length": 0,
"name": "abs_long",
"precision": 0,
"type": 6,
},
{
"expression": '"axis_x"',
"length": 0,
"name": "axis_x",
"precision": 0,
"type": 6,
},
{
"expression": '"axis_y"',
"length": 0,
"name": "axis_y",
"precision": 0,
"type": 6,
},
{
"expression": "''",
"length": 0,
"name": "layers",
"precision": 0,
"type": 10,
},
{
"expression": '"p_id"',
"length": 0,
"name": "p_id",
"precision": 0,
"type": 10,
},
{
"expression": TOPO_BAT_EXPR,
"length": 0,
"name": "topo_bat",
"precision": 0,
"type": 10,
},
{
"expression": '"abs_lat"',
"length": 0,
"name": "abs_lat",
"precision": 0,
"type": 10,
},
{
"expression": '"zfond"',
"length": 0,
"name": "zfond",
"precision": 0,
"type": 10,
},
],
"OUTPUT": output
},
)
return {self.OUTPUT: output}
def name(self):
return "repair_profiles"
def displayName(self):
return self.tr("Repair profiles layer")
def shortHelpString(self):
return self.tr(
"This algorithm repair a profiles layer by adding missing topo_bath field."
)
def group(self):
return self.tr("Profiles")
def groupId(self):
return "Profiles"
def createInstance(self):
return RepairProfilesAlgorithm()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment