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 ?

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

answered Jul 21, 2023 at 1:29
1
  • 1
    Kindly accept the answer. Commented Aug 8, 2023 at 20:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.