I am trying to set a Project Variable with QGIS Modeler with values as the modeler calculates them. In this case I am trying to get the calculated area from a process "Fire_Area" written to a project variable that can be input into the map sheets or atlas etc. Everything works but the write to the variable fails. See attached images.

Modeler enter image description here enter image description here

1 Answer 1


Since field calculator will evaluate the expression for each feature, it seems like you want to assign a kind of dynamic value to a project variable name.

You can't that way, because custom project variables accepts only string literal values. In fact, they will be stored as a string in the project file.

You probably don't need it, but you could set the expression text, and evaluate it in any other context of the expressions builder, as long as the built-ins you use in the expression are valid in that context.

For example, @feature built-in variable and $area function are valid in a field calculator context.

You can fill a field value with the ellipsoidal area of each feature's geometry (regardless of its crs) with:


For the planimetric area (dependent on its crs) you can:

area( geometry( @feature))

Although simpler:

area( @geometry)

In all those cases, you are assigning a value to a property (for example the fire_area property) of each feature, by filling its field. This is what is generally done when you want a "dynamic value based on each feature".

But nothing prevents you from set the literal text of the expression in a project variable called, for instance, fire_area_expr:


And then you can evaluate it in a field calculator:

eval( @fire_area_expr)

Fortunately, both built-ins (@feature and $area) can also be used in the context of atlas page filters, or labels of an atlas-controlled layout. Therefore that project variable can also be used there, in the same way.

In any case, if you want to set a custom project variable from a model output, it has to be a text. It can be a text input of the model, or an expression algorithm output returning a text. And it can be then evaluated as a expression in a context.

If you already filled the fire_area field of each feature with the area value, you could also use:

attribute( @feature, 'fire_area')

Or simpler:


The with_variable function creates a fleeting variable, which value can store absolutely any type of data:

 'fire_area_var', --the variable name
 $area, --the expression to compute its value
 @fire_area_var --an expression calling the variable value by its name

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.