[GIS] QGIS 3 Graphical Modeler field calculator with attribute’s parameters

field-calculatorqgis-3qgis-modeler

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

Best Answer

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

Related Question