I am building a model in the graphical modeler of QGIS 2.8.1 Wien and I would like to give the option to the user to enter a number in the model with which a selected field will be multiplied, but I cannot figure out how to connect the parameter for the user input to the field calculator algorithm.

Any ideas on this?

  • As I can see there this question already exists here but for older version: gis.stackexchange.com/questions/72569/…
    – Eleftheria
    Commented Oct 2, 2015 at 7:32
  • 1
    I also have trouble getting it to work through the modeler. Have you considered converting your model to a Python script? You would still get the same interface when running the script as you would with the modeler but it allows you to edit code such as including user input. Hopefully others can advise on how to get this to work through the modeler :)
    – Joseph
    Commented Oct 2, 2015 at 12:43
  • Thank you for your answer. I have considered converting the model toy python script but Toolbox does not give me the option by rigth clicking on the model to save it as .py
    – Eleftheria
    Commented Oct 2, 2015 at 19:34
  • 1
    An early version had that option. You would have to downgrade the Processing plugin to version to 2.2.0-2. Download and extract the folder to (if you're on Windows) C:\Users\You\.qgis2\python\plugins. Note that there might be algorithms not be available in the old version compared to the newer ones. I suggest you back up your C:\Users\You\.qgis2\processing folder as this contains models/scripts in case something happens.
    – Joseph
    Commented Oct 5, 2015 at 9:43

1 Answer 1


Instead of using the Field Calculator tool, a possible workaround is to create a custom script which allows the user to choose an attribute field and update it with a value they enter.

To do this, go to Processing Toolbox > Scripts > Tools > Create new script and copy the following:

##Update field by number=name
##Fields=Field Layer
##Number=number 0

from qgis.core import QgsExpression

layer = processing.getObject(Layer)  

idx = layer.fieldNameIndex(Fields)
n = str(Number)
i = str(Fields)
e = QgsExpression(n + '*' + i)

for f in layer.getFeatures():
    f[idx] = e.evaluate(f)


Save the script into C:/Users/You/.qgis2/processing/scripts. You will need 3 parameters:

  • Layer - Vector layer
  • Field - Table field
  • Number - Number

Then add the script from the list of algorithms to your model. Use the Parent algorithms option if you want this script to run after a specific tool (i.e. at the end of the model).:


Did a simple test where I want to update the id field by entering 5 in the Number parameter. Here is the attribute table initially:

Original attributes

Setting and running the model:

Setting model




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.