3

My model start by asking two input layer LAYER1 and LAYER2.

Then, in field calculator for LAYER1, i want to join an attribute value from LAYER2. Using this code :

attribute( get_feature( 'LAYER2','ID1',"ID1"),'FIELD1')

enter image description here

The problem is that I'm not able to know the name of the input layer LAYER2 So I try to use the layer_property in order to see if the modeler recognize the name of yhe valeur but he won't:

layer_property( @LAYER2 ,'layerName')

enter image description here

enter image description here

But it always return a NULL value. Is there is something that you have to done to return the name of the layer?

0
0
  1. Make sure your layers are the Vector Layer type in your model, not just Map Layer.
  2. Add Vector Field elements to your model. You will be able to select the corresponding layer under Parent Layer.

vector fields

  1. Add the Field Calculator algorithm to your model. In it, specify the appropriate layer and field being calculated. Because you've made your join attribute a model parameter, you can now call it with an '@'. I've only put @ID in for an example, but this could easily be a get_attribute() expression to grab the specific feature you want.

field calculator parameters

Now when you run the model, you will be prompted to select the join field, and it should work as you intended.

running model

2
  • Thanks for your time, but that's not answered my question :) I know the field name because it's normalized. But I can't know the name of the input layer. So this the formula: aggregate ('LAYER1','max',"FIELD1", intersects ($geometry, start_point (geometry (@parent))). LAYER 1 is the input layer she could be called LAYER1 or 2 or whatever but I don't know that. I need to call the layer name in order to make this spatial join. I work with the extension NETWORKS because I can't create another layer so I need to update the input layer.
    – Lelevdl
    Oct 20 '20 at 7:35
  • You say you need to call the layer name to complete the join, but that you don't know the layer name. Perhaps you have misread my answer, but that is the entire point of using model parameters to represent the field names as well as the layers. I can put any two layers and any of their fields into this model, whether I know their names ahead of time or not, and the model will still run correctly.
    – JoshC
    Oct 20 '20 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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