5

I want to use the Field Calculator inside the Graphical Modeler to create a new column in an input vector layer (LAYER1) using data in another layer (LAYER2). LAYER2 is the output of another algorithm inside the model.

The formula is as follows:

attribute(get_feature("LAYER2", 'WKT', geom_to_wkt(start_point($geometry))) , 'NODEID')

Actually, I am trying to implement an algorithm similar to what's described in Getting points-touching-a-line attributes back to lines layer using QGIS?.

When used outside the model, it works perfectly.

When used inside the model, the column is always created with NULL values.

Any ideas on how to reference LAYER2 inside the Field Calculator for this to work?

  • Hit the same problem. Tried using the saved name of the layer, the one presented in the GUI ("X from algorithm Y"), but neither are found. The dependencies are set up properly. Log shows temporary names only — any way to catch those? – lynxlynxlynx Sep 9 '18 at 12:20
  • 1
    What about a join? Field Calculator always works on only one single layer. – Stefan Sep 9 '18 at 15:20
  • Maybe there's a way to save the desired 'WKT' value from "LAYER2" as a variable within the model. Then you could use that variable in the Field Calculator instead of your attribute(get_feature()) formula. – csk Sep 9 '18 at 16:07
  • @Stefan_Fairphone It can work on multiple, that's why the functions. The problem is just in the modeller context. If you have a concrete idea with a join, please provide an answer. – lynxlynxlynx Sep 10 '18 at 17:41
  • 1
    You would need a key attribute that is the same for a feature in both layers. Do you have such a key attribute (some kind of ID, etc.)? – Stefan Sep 10 '18 at 21:30
2
+50

The idea would be to create the join and then create the field:

  1. Create geometry from WKT on LAYER2 using Geometry by expression
  2. Extract the start point of LAYER2 using Extract specific vertices and specify first vertex (index 0).
  3. Join using Join attributes by location using the output of previous alg and of LAYER1.
  4. Use the Field Calculator using the joined field
  • This can easily hit the same referencing problem at #1. – lynxlynxlynx Sep 11 '18 at 6:44
  • If you know the field name you can use it directly in the expression since it is joined. Or am I missing something? – Denis Rouzaud Sep 11 '18 at 13:02
  • I think I just got confused, you've switched OP's layer 1 and 2. – lynxlynxlynx Sep 11 '18 at 21:07

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.