Hi,
I've read lots of forum questions and tips but don't know how to solve my case.
I am using the expression generator to create 2 symbologies. I have a table with 5 fields/
I would like to define 2 groups:
Solved! Go to Solution.
// get an array of the $feature's values
var values = [$feature.GewässerID, $feature.BescheidID, $feature.EinzugsgebietID, $feature.KontaktID, $feature.ASVNummer]
// get the count of non-empty values
var c = 0
for(var i in values) {
c += !IsEmpty(values[i])
}
// return true if 2 or more values are non-empty
return c >= 2
// get an array of the $feature's values
var values = [$feature.GewässerID, $feature.BescheidID, $feature.EinzugsgebietID, $feature.KontaktID, $feature.ASVNummer]
// get the count of non-empty values
var c = 0
for(var i in values) {
c += !IsEmpty(values[i])
}
// return true if 2 or more values are non-empty
return c >= 2
Thank you for this answer. It worked.
Now could you explain me how this part works?
// get the count of non-empty values
var c = 0
for(var i in values) {
c += !IsEmpty(values[i])
}
IsEmpty returns a boolean value (true or false). ! is the symbol for "not", it reverses the boolean output. !IsEmpty(value) returns true if the value is not empty.
Booleans can be converted to numbers (true = 1, false = 0). Arcade can do that implicitly, without needing the explicit instruction to do so.
So this code declares a variable c and sets its value to 0. Then it goes through the array of values. For each of those values, it adds the numeric equivalent (0 or 1) of "This value is not empty" to c. So if the value is empty, it adds 0, if the value is not empty, it adds 1. It basically counts the non-empty elements in the array.
What a great explanation. Cheers