If I have a geoalgorithm in my model and I want the value from one the parameters, then how can I get it? For example I want the layer name in the parameter layer
in below figure so I get the value Pts1
.
-
1Is the layer name hard-coded into your model or is it one of the inputs of the model?underdark– underdark2015年12月25日 21:52:23 +00:00Commented Dec 25, 2015 at 21:52
1 Answer 1
Don't think you could do this directly through the modeler but you could create a custom script which, when run can simulate a model, allows you to fetch the name of the layer and use it for processing.
The following script uses the Field Calculator tool which creates a new field with the layer name and populates the values with the layer name (the python command is layer.name()
):
##Fetch layer name=name
##Layer=vector
##Result=output vector
layer = processing.getObject(Layer)
processing.runalg("qgis:fieldcalculator", Layer, layer.name(), 2, 99, 0, True, "'" + layer.name() + "'", Result)
You can have a look at the documentation on how to create scripts and call various functions and their associated parameters: