I am writing a Python script that I will add in to my processing toolbox. I have got the script working so now just a case of setting my Inputs and Outputs. I am struggling with one, I am trying to set it so the user can enter multiple layers as one of the inputs just like how it is set up on the Merge Vector Layer tool below.
I have been trying the following two bits of code to try and set this up but it's a bit of a guess really.
How do I correctly format these?
self.addParameter(
QgsProcessingParameterMultipleLayers(
name,
description,
QgsProcessing.TypeVectorAnyGeometry
)
)
Map = self.parameterAsLayerList(
parameters,
name,
context
)
-
What's the question here :)? I think you've nailed it with the code snippets you posted. That's the way of adding such a parameter to a processing script as well as to read it.Germán Carrillo– Germán Carrillo2021年08月21日 02:26:36 +00:00Commented Aug 21, 2021 at 2:26
1 Answer 1
A simple example of usage is below. Don't forget to import the QgsProcessingParameterMultipleLayers
class.
...
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterMultipleLayers(
'LAYERS',
self.tr("Input layers"),
QgsProcessing.TypeVectorAnyGeometry))
def processAlgorithm(self, parameters, context, feedback):
layers = self.parameterAsLayerList(parameters, 'LAYERS', context)
for layer in layers:
#do something with layer
...