Expression based symbology with multiple !IsEmpty

429
4
Jump to solution
10-04-2022 02:17 AM
arthurV
New Contributor III

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:

  • Group A: features with 2 (or more) fields non empty
  • Goup B: else (features with only one non empty field)

 

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

JohannesLindner_0-1664876667687.png

 

// 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

JohannesLindner_1-1664876836747.png

 


Have a great day!
Johannes

View solution in original post

4 Replies
JohannesLindner
MVP Frequent Contributor

JohannesLindner_0-1664876667687.png

 

// 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

JohannesLindner_1-1664876836747.png

 


Have a great day!
Johannes
arthurV
New Contributor III

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])
}

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

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.


Have a great day!
Johannes
arthurV
New Contributor III

What a great explanation. Cheers

0 Kudos