1

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

  • Have you tried this expression manually? – Erik Aug 29 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" – Alejandro Chamizo de Castro Aug 29 at 11:39
  • What do "A" & "B" stand for? Are they actual columns in the joined layer? – Erik Aug 29 at 11:40
  • Yes, they are 2 columns existing in the original layer. I would like to average two values (A + B) / 2 – Alejandro Chamizo de Castro Aug 29 at 11:50
1

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

  • 1
    Thanks @joseph. Run perfectly – Alejandro Chamizo de Castro Aug 29 at 12:14
  • @AlejandroChamizodeCastro - Most welcome, glad it helped :) – Joseph Aug 29 at 12:18

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.