[Qgis-user] Model desinger / enum input question

Bo Victor Thomsen bo.victor.thomsen at gmail.com
Thu Jun 12 09:15:20 PDT 2025


Okay, no answers for the question.

For future reference (if others have the same problem and find this 
posting) :

You can use an array constructor together with the array_get function

i.e., if you have an Enum processing input  "animals" with values like 
"Gorilla","Snake" and "Elephant", you can get the enum textual value by 
using this construct:

*array_get(array('Gorilla','Snake','Elephant'), at animals)*

It's not pretty - but it much shorter than writing a potentially 
humongous CASE..WHEN construct.
An even better method would be to use a (hypothetical)  function that 
returns a list of enumeration texts based on the name of the input, like

*array_get(enum_texts('animals'), at animals) *or - even better 
-***enum_text('animals',**@animals**)*

However, i haven't found these hypothetical functions.

Med venlig hilsen / Best regards

Bo Victor Thomsen

On 10/06/2025 12.35, Bo Victor Thomsen wrote:
> Hi list -
>
> I'm designing a processing model, where i use a "Enum" input. When 
> accessing this variable in a "Calculate Expression" algorithm in the 
> model, the result will be an ordinal value - not a text - from the enum.
>
> Example:
> I have an enum named "animal" defined with 3 animal names like 
> "Gorilla","Snake","Elephant". If the user choose "Snake" the variable 
> @animal contains the number "1" instead of "Snake". How do I get the 
> textual representation of the enum instead of the ordinal ?
>
> I'm aware I can use a CASE... WHEN in the expression. But it will be 
> cumbersome for enums with many values.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20250612/fd382994/attachment.htm>


More information about the QGIS-User mailing list