Select to view content in your preferred language

Conditional Symbology based on Arcade Script?

336
6
02-21-2025 12:59 PM
Labels (1)
JoseLGonzalez
Emerging Contributor

I'm trying to set up conditional symbology by turning the contents of the highlighted row, under the column “ALL_UNITS” into an array. So the array should contain the elements: E29, E64, E82, E244, and E286. Once the array is established, the script should check the column RedUnits for matches. Therefore, the points for STANUM 29 should have the “White Yellow” symbology.

Screenshot 2025-02-21 113709.pngScreenshot 2025-02-21 113824.png

var st1102 = IIf($feature["STANUM"] == 1102, $feature["ALL_UNITS"], null);

var st1102array = Split(st1102, ",");

if (Includes(st1102array, $feature.RedUnits))

return "White Yellow";

else if ($feature.RedUnits == null && $feature.GreenUnits == null && $feature.BlueUnits != null)

return "Brown";

else if ($feature.RedUnits == null && $feature.GreenUnits != null)

return "Grey";

else if ($feature.RedUnits != null)

return "White";

else

return "Black";

0 Kudos
6 Replies
KenBuja
MVP Esteemed Contributor

One thing I see is that st1102array is ["E29"," E64"," E82"," E244"," E286"]. Note that there is a space before all of text elements except the first. This means that if RedUnits was "E64", it would return "White" instead of "White Yellow". You should use ", " instead of "," for the separator in the Split function.

The other thing I see is if there are two items in RedUnits (STATNUM  33), it would return "White". You can split RedUnits into an array to check if any of them match.

This should work properly

var st1102 = IIf($feature["STANUM"] == 1102, $feature["ALL_UNITS"], null);
var st1102array = Split(st1102, ", ");
var RedUnitsArray = Split($feature.RedUnits, ", ");

for (var i in RedUnitsArray) {
  if (Includes(st1102array, RedUnitsArray[i])) return "White Yellow";
}

if (
  $feature.RedUnits == null &&
  $feature.GreenUnits == null &&
  $feature.BlueUnits != null
)
  return "Brown";
else if ($feature.RedUnits == null && $feature.GreenUnits != null)
  return "Grey";
else if ($feature.RedUnits != null) return "White";
else return "Black";

 

 

0 Kudos
JoseLGonzalez
Emerging Contributor

Thanks so much for the reply @KenBuja.

Your script yielded an interesting result, the only points that got the White Yellow symbology are three test points I created with null values in the RedUnits column. 

Screenshot 2025-02-21 140049.png

0 Kudos
KenBuja
MVP Esteemed Contributor

I was testing with dummy data and didn't include the IIf statement, which threw things off. Here's the testing code with an update in line 13 in this code (line 6 of the previous code)

var STANUM = 1102;
var ALL_UNITS = "E29, E64, E82, E244, E286"
var st1102 = IIf(STANUM == 1102, ALL_UNITS, null);

var RedUnits //= "E29"
var GreenUnits //= "Q30"
var BlueUnits //= "S32"

var st1102array = Split(st1102, ", ");
var RedUnitsArray = Split(RedUnits, ", ");
console(st1102array, RedUnitsArray)
for (var i in RedUnitsArray) {
  if (!IsEmpty(st1102) && Includes(st1102array, RedUnitsArray[i])) return "White Yellow";
}

if (
  RedUnits == null &&
  GreenUnits == null &&
  BlueUnits != null
)
  return "Brown";
else if (RedUnits == null && GreenUnits != null)
  return "Grey";
else if (RedUnits != null) return "White";
else return "Black";

This allowed me to test different scenarios, like changing STATNUM and the units to verify that each of the returns work.

0 Kudos
JoseLGonzalez
Emerging Contributor

Thanks for continuing to work on this, @KenBuja.

Unfortunately, the updated script gave only black points. 

Screenshot 2025-02-24 111924.png

0 Kudos
KenBuja
MVP Esteemed Contributor

Unfortunately, without access to your data, there's not much more I can do. I made sure each of the possible combinations of variables in my test code would give the expected response. For example, changing this line

var GreenUnits = "Q30"

 returns "Grey"

0 Kudos
JoseLGonzalez
Emerging Contributor

Copy that. I appreciate your efforts, Ken! 🙏

0 Kudos