6

So I start my model by dragging an input layer, which in my case it happens to be a vector layer. Let's call it inputVectorLayer. Later on in the model I want to refactor this layer using the Refactor fields algorithm. For each feature I write the correct expression, but for one feature I need an expression that should include something like this:

layer_property('inputVectorLayer', 'name')

The problem is that it doesn't recognize the name that I gave to the representation of the input layer in the Model Builder. How can I achieve this?

If I do something like this:

layer_property('actualLayerNameAsItShowsInTheLayesPanel','name')

it works, but obviously, this name changes. That's the whole point of the module, to use aliases to reference input layers. I already tried to use double quotes to no avail layer_property("inputVectorLayer", 'name')

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 19, 2018 at 11:49
3
  • Did you find any solution to this ? Commented Dec 20, 2022 at 23:51
  • @CésarArquero Sorry. I even forgot what I was up to at the time. I don't think I found any solution and I can't even check, as I just don't know when and what I used the QGIS modeler for. This shows that I managed to create a good general question out of my particular use case, but it also means that I'm looking at this question as if it's the first time I'm seeing it. Commented Dec 22, 2022 at 13:03
  • 1
    Thanks for replying. I found that changing the input to "vectorial objects" the layer_property function actually works. Here is a solution for something similar: gis.stackexchange.com/questions/446636/… Commented Dec 22, 2022 at 15:43

2 Answers 2

5

It might be too late but I just faced the problem today... You can do it with the layer_id:

 layer_property(@layer_id, 'name')
Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
answered Mar 6, 2018 at 12:38
1
  • Note that @layer_id only references the input layer when it is used in the first tool connected to that input. So the name will need to be stored (as an attribute) if it is required later in the model. There are variables of the parameters exposed, but a 'Vector layer' input variable is not of <layer> or <layerid> type seemingly... Commented Mar 15, 2019 at 14:27
2

Here is a possible solution: Using input parameter as part of SQL query in QGIS model

Currently, the layer_property function doesn't work with and input like "vectorial layer", but it works with the "vectorial objects" input. As all the other inputs work equally with this input, attributes from layer for example, if you just change the input you can get the layer properties with that function.

I hope it helps.

answered Dec 22, 2022 at 15:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.