6

I want to make a model with a vector layer to calculate the sum of two parameters contained in the attribute table of the layer.

I want to create two variables in the model, the name of the two fields of the attribute table to use in the model for the calculation of the new field (A and B), but the geoprocess of the advanced field calculator with python does not get to configure so that you can relate those two variables. model

4
  • Have you tried this expression manually?
    – Erik
    Commented Aug 29, 2019 at 11:24
  • Sure, but the layer result is empty, maybe not work. I suspect that he does not recognize the variables "A" and "B" Commented Aug 29, 2019 at 11:39
  • What do "A" & "B" stand for? Are they actual columns in the joined layer?
    – Erik
    Commented Aug 29, 2019 at 11:40
  • Yes, they are 2 columns existing in the original layer. I would like to average two values (A + B) / 2 Commented Aug 29, 2019 at 11:50

1 Answer 1

8

Use the normal Field Calculator and in the Formula option, select Pre-calculated Value. Then use the expression:

'(' || @a || ' + ' || @b || ') / 2'

where the parameters @a and @b are the fields you assign when running the model. This is read by the field calculator as a string version of:

(A + B) / 2

Modeler field calculator

2
  • 1
    Thanks @joseph. Run perfectly Commented Aug 29, 2019 at 12:14
  • @AlejandroChamizodeCastro - Most welcome, glad it helped :)
    – Joseph
    Commented Aug 29, 2019 at 12:18

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.