I am trying to label a feature based on if it is in particular criteria. There are address points where we want to label the Situs Number (SitusNum) based only if the Description of the address is 'SINGLE'. The code below is obviously basic but I am wondering how I can apply a when or if statement to below. We will be using multiple expressions in the same label class, so applying a SQL filter will not be enough.
$feature.SitusNum
SQL Statement to make it so it labels only where the description is NULL:
Description = 'SINGLE'
Solved! Go to Solution.
A straight "translation" of that code might look like this:
var d = $feature.Description
var s = $feature.SitusNum
var u = $feature.myUnitVal
if(d == 'SINGLE'){
return s
} else if(d == 'DUPLEX'){
if(IsEmpty(u)){
return s
} else{
return s + ' - ' + u
}
Note the function IsEmpty returns True if the value is null or an empty string.
Maybe it's just me, but it's not entirely clear what your end goal is here based on the code you've shared. Can you elaborate on what the "multiple expressions" are, and give an example of what the expected output might be?
If you're just looking for how to implement a series of "if... else if... else" statements, the Arcade guide details this thoroughly.
Thanks, Josh,
To clarify, I am looking to label the Situs Number of the address where the description of the address is single. We label different addresses in different ways that we are trying to convert from VB Script into Arcade. The example below shows how we labeled single addresses, then how we labeled duplexes in the same label class.
Function FindLabel ([Description], [SitusNum], [BuildingNum], [UnitNum])
myDescrip = [Description]
myBldgVal = [BuildingNum]
myUnitVal = [UnitNum]
Select Case myDescrip
Case "SINGLE"
FindLabel = [SitusNum]
Case "DUPLEX"
if isNull(myUnitVal) or myUnitVal = "" or myUnitVal = " " then
FindLabel = [SitusNum]
else
FindLabel = [SitusNum] & " - " & [UnitNum]
A straight "translation" of that code might look like this:
var d = $feature.Description
var s = $feature.SitusNum
var u = $feature.myUnitVal
if(d == 'SINGLE'){
return s
} else if(d == 'DUPLEX'){
if(IsEmpty(u)){
return s
} else{
return s + ' - ' + u
}
Note the function IsEmpty returns True if the value is null or an empty string.
So when I enter that, it shows that there is a reserved keyword on line 10.
else{
Thanks, @KenBuja ! I'm used to interfaces that auto-insert my braces and brackets, and that one got by me. I should write it up in an IDE first to catch those sorts of mistakes.
@jcarlson , would you have any knowledge as to how to treat labeling an address with the same description based on the code snippets from above. Below, if a feature is a business, I am trying to label the building number only, not the situs number if a building number exists. In the same scope of work, I am also trying to label a business on the unit number only if a unit number exists.
}else if(d == 'BUSINESS'){
if(IsEmpty(u)){
return s}
else{
return u}
} else if(d == 'BUSINESS'){
if(IsEmpty(b)){
return s}
else{
return b}
}
Thank you both for your assistance on this, greatly appreciated.