Arcgis Pro Calculate field IIf arcade Or Python

480
3
Jump to solution
07-20-2021 12:31 AM
Labels (1)
LucileFayolle
New Contributor II

I want to calculate a filed and struggle to understand how to code the expression.

var TrapType = $feature.Trap_type;
IIf(TrapType = "Trapinator" or "Timms" or "Set & forget" , 'Possum', 'Rat');

What I would like:

If Trap_type=  "Trapinator" or "Timms" or "Set & forget"  --> Target_specie = 'Possum'
If Trap_type = other stuff --> Target_specie = 'Rat'

0 Kudos
2 Solutions

Accepted Solutions
JohannesLindner
MVP Regular Contributor
// test for equal with ==
// Aracade doesn't have and/or/not, it uses &&/||/!
// test for equality has to be repeated

var TrapType = $feature.Trap_type;
IIf(TrapType == "Trapinator" || TrapType ==  "Timms" || TrapType ==  "Set & forget" , 'Possum', 'Rat');

// easier:
IIF(Includes(['Trapinator', 'Timms', 'Set & forget'], TrapType), 'Possum', 'Rat');

Have a great day!
Johannes

View solution in original post

JohannesLindner
MVP Regular Contributor
# same goes for python, except you can use and/or/not

TrapType = !TrapType!
return 'Possum' if TrapType == 'Trapinator' or TrapType ==  'Timms' or TrapType == 'Set & forget' else 'Rat'

# easier:
return 'Possum' if TrapType in ['Trapinator', 'Timms', 'Set & forget'] else 'Rat'

Have a great day!
Johannes

View solution in original post

3 Replies
JohannesLindner
MVP Regular Contributor
// test for equal with ==
// Aracade doesn't have and/or/not, it uses &&/||/!
// test for equality has to be repeated

var TrapType = $feature.Trap_type;
IIf(TrapType == "Trapinator" || TrapType ==  "Timms" || TrapType ==  "Set & forget" , 'Possum', 'Rat');

// easier:
IIF(Includes(['Trapinator', 'Timms', 'Set & forget'], TrapType), 'Possum', 'Rat');

Have a great day!
Johannes
JohannesLindner
MVP Regular Contributor
# same goes for python, except you can use and/or/not

TrapType = !TrapType!
return 'Possum' if TrapType == 'Trapinator' or TrapType ==  'Timms' or TrapType == 'Set & forget' else 'Rat'

# easier:
return 'Possum' if TrapType in ['Trapinator', 'Timms', 'Set & forget'] else 'Rat'

Have a great day!
Johannes
LucileFayolle
New Contributor II

Thank you soo much!

have a great day too

Lucile

0 Kudos