I am writing a plugin to convert degree to DMS format. I want to name the output layer containing name of source layer. For example source layer name 'Polygons_WGS84', output layer 'Polygons_WGS84_to_DMS'.
I tried to change name of processed_layer but setName()
not working. Output layer name still is 'Output'.
A similar problem was solved by the link postProcessAlgorithm in processing algorithm for QGIS 3.10
def processAlgorithm(self, parameters, context, feedback):
.............................................
# Add a feature in the sink
sink.addFeature(new_feature, QgsFeatureSink.FastInsert)
# Take input layer name
inp = self.parameterAsLayer(
parameters,
self.INPUT,
context)
# Output layer name
out = f'{inp.name()}_to_DMS'
processed_layer = QgsProcessingUtils.mapLayerFromString(dest_id, context)
processed_layer.setName(out)
return {self.OUTPUT: dest_id}
Best Answer
You can change it in
def initAlgorithm()
. Just enter the name you wish in the specific parameter withinself.tr()
:To make the name dynamic, you need to follow this answer like this:
Here is the complete example from QGIS template, with this part added: