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
If adding new fields to your layer is an option for you, you can do it the following:
Save your two values into the fields "fixvalue" and "varvalue"
Save your expression into a field ("expression") using the string indicator
'
(single quote) like this:'("fixvalue" * "varvalue")'
You can now calculate your result using the expression
eval( "expression")
. The expressioneval()
turns a string into an expression.The result
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:
update the result:
the new result:
-
1Instead 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– csk2020年01月25日 19:54:43 +00:00Commented Jan 25, 2020 at 19:54
-
Thanks csk! I never used the layer level variables, it opens up many new possibilities.rtaani– rtaani2020年01月27日 07:10:54 +00:00Commented 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– rtaani2020年01月27日 07:13:52 +00:00Commented Jan 27, 2020 at 7:13