This is the first QGIS Process Model I have ever attempted to build (and I am still on a learning curve with QGIS generally).


I need to build a model that will take an input vector and (1) rename it (the name must come from an attribute value stored within the layer), (2) clip it against another polygon, (3) and finally add a pre-defined style.


The input layers will always have the same name i.e. "2D Zones" there is no way around this as they are outputs from another piece of software and this cannot be changed. The fields for these input layers will always have the same names and will be arranged in the same order, the attribute values will differ.

There is a field within each "2D Zones" table called "retperiod" the value appearing in that column will be the same throughout the whole column but will differ from layer to layer, so this is the attribute I want to use as a name.


After reading the solutions to similar problems posted here:

I have managed to come up with a model that performs the task I wish it to do (see link).


I have also read all this lot (although probably haven't understood it all):


However, one shortcoming of my model is that I have to specify the input layers as both a "Vector Features" and a "Vector Layer" input. This seems to be because I can only the Modeller won't allow the "get_feature_by_id" function to work on the "vector layer" input but it will work on the "vector feature" input..... Essentially, this model will only complete the renaming routine, i.e. this bit:


If I get it to look in the "vector feature" input for the attribute that can be used as a name but then it must be applied to the input from "vector layer" in order for the subsequent processes (i.e. clipping and styling) to work.

All very unintuitive.


Is there a more elegant solution to all this whereby I don't have to specify the same inputs twice in two different ways?

This is still problematic as the original files all have exactly the same name and there is every chance I will match the two inputs incorrectly when using the "batch process" option.

1 Answer 1


Use the Rename Layer algorithm, set the New name input to Pre-calculated Value and insert an expression that gets the value of the attribute retperiod from the input layer. The input layer is available as a context variable in the expression string builder.

The expression to use looks like:

attribute (get_feature_by_id (@load_vector_layer, 1),'retperiod')

enter image description here

  • If I were to implement your suggestion I could use the "rename" algorithm as soon as the input vector is added to the model: no point in this as the clipping procedure requires the output to be renamed "clipped" unless you re-specify a name. Logically then, I could do it on the model output.... not so; Jan 23, 2023 at 9:43
  • "attribute (get_feature_by_id (@load_vector_layer, 1),'retperiod')" doesn't seem to work on vector layers only on vector objects (please see third hyperlink on my original post). This is very much the source of my confusion as your suggested solution looks logical, but in practice; the "attribute()" statement just returns "NULL" and the model fails on this basis. Jan 23, 2023 at 9:43
  • I think the difference between what you did with your previous example (i.e. first hyperlink: which I am trying to copy) and what I am doing is that your model might be referring to a saved layer that you have downloaded with some fixed address, my model is trying to rename a virtual layer that is output from an algorithm and thus not saved. (possibly??). Jan 23, 2023 at 9:47
  • OK, I see I was maybe referring to another case. Just renaming the layer this way worked in my case, with the expression provided.
    – Babel
    Jan 23, 2023 at 10:10
  • Well thanks for your input anyway! :-) I really can't understand why your solution doesn't work in my case to be honest. I can see that QGIS seems to point blank refuse to use "@input vector layer" but is happy enough with "@input vector feature" but I have no idea why this is the case. Jan 23, 2023 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.