0

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.

enter image description here

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?

enter image description here

What should I use instead of @FieldChoice in the FieldCalculator algorithm ?

3
  • 1
    may be this answer helps you: gis.stackexchange.com/a/453048/87346
    – eurojam
    Commented 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
    Commented Jul 20, 2023 at 3:43
  • 1
    @eurojam Thanks, I have figured it out, I will share the answer.
    – GforGIS
    Commented Jul 20, 2023 at 5:20

1 Answer 1

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.

enter image description here

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'

enter image description here

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

1
  • 1
    Kindly accept the answer.
    – Padmanabha
    Commented Aug 8, 2023 at 20:39

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.