2

I'm using QGIS 3.10.0 A Coruna.

I'm using the field Calculator for an equation which requires a variable (which I Type in manually) and a (fixed) value within the same attribute table. This variable is different for each feature, meaning I have to write the equation (for my example) 55 times.

I dont have a problem with that so far; however, if for any reason my fixed value should change, I would have to repeat the work with the field calculator over and over again. Is there a way where

1) I can see which equation I used in the first place and

2) where I can automatically update my results in the attributetable in case the fixed value changes?

1 Answer 1

3

If adding new fields to your layer is an option for you, you can do it the following:

  1. Save your two values into the fields "fixvalue" and "varvalue"

  2. Save your expression into a field ("expression") using the string indicator ' (single quote) like this: '("fixvalue" * "varvalue")'

enter image description here

  1. You can now calculate your result using the expression eval( "expression"). The expression eval() turns a string into an expression.

  2. The result

enter image description here

When you now change your fixed value by using field calculator -> update fields, you can easily recalculate your result by using the expression in #3 like this:

Update the fixvalue:

enter image description here

update the result:

enter image description here

the new result:

enter image description here

3
  • 1
    Instead of saving the fixed value in a field, you can save it as a layer level variable. That way you only have to change it in one place when you change the fixed value.
    – csk
    Jan 25, 2020 at 19:54
  • Thanks csk! I never used the layer level variables, it opens up many new possibilities.
    – rtaani
    Jan 27, 2020 at 7:10
  • MrXsquared, thank you for the elaborate answer! I didnt know the "eval" funktion - I might just be able to combine your and csk answers, so I dont have that many new fields!
    – rtaani
    Jan 27, 2020 at 7:13

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.