In the Graphical Modeller in QGIS, I am trying to extract the values of a field in a Layer by using the "Vector Field" parameter (named FieldChoice in my case) in the Field Calculator.
When opening the filed calculator, I wanted to use the Value of the field selected by the user, however when using @fieldchoice as a parameter it will return the field name instead of its value. What would be the way to retrieve the attributes in the field for the calculation instead of the field name?
What should I use instead of @FieldChoice in the FieldCalculator algorithm ?
-
1may be this answer helps you: gis.stackexchange.com/a/453048/87346eurojam– eurojam2023年07月19日 05:24:52 +00:00Commented Jul 19, 2023 at 5:24
-
@eurojam I have edited my question as there was a mistake, but you understood what I meant though. I just can't get it running. I will continue working on it.GforGIS– GforGIS2023年07月20日 03:43:32 +00:00Commented Jul 20, 2023 at 3:43
-
1@eurojam Thanks, I have figured it out, I will share the answer.GforGIS– GforGIS2023年07月20日 05:20:38 +00:00Commented Jul 20, 2023 at 5:20
1 Answer 1
I followed the instructions on the post provided by @eurojam gis.stackexchange.com/a/453048/87346 and managed to get my algorithm to work.
I had to use the "Pre-calculated Values" to extract the values from the field @fieldchoice. My final expression used is:
'(' || '(' || @fieldchoice || '- $area' || ')' || '/' || '$area' || ')' || '* 100'
I would like to emphasis on the use of " ' " and " || " to concatenate the string forming the expression. I was using " + " instead of " || " even though both can concatenate strings, however " + " can be also used as an operator to add numbers.
The following document helped me to understand better how to resolve the issue:
https://docs.qgis.org/3.10/en/docs/user_manual/working_with_vector/expression.html
-
1Kindly accept the answer.Padmanabha– Padmanabha2023年08月08日 20:39:03 +00:00Commented Aug 8, 2023 at 20:39