Label in Arcade based on domain value?

921
8
Jump to solution
04-26-2021 07:43 AM
Labels (1)
Brian_McLeer
Occasional Contributor II

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'

Brian
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Frequent Contributor

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.

- Josh Carlson
Kendall County GIS

View solution in original post

8 Replies
jcarlson
MVP Frequent Contributor

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.

- Josh Carlson
Kendall County GIS
Brian_McLeer
Occasional Contributor II

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]

 

 

Brian
0 Kudos
jcarlson
MVP Frequent Contributor

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.

- Josh Carlson
Kendall County GIS
Brian_McLeer
Occasional Contributor II

So when I enter that, it shows that there is a reserved keyword on line 10.

else{

Brian
0 Kudos
KenBuja
MVP Honored Contributor

There's a missing "}" before the "else"

jcarlson
MVP Frequent Contributor

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.

- Josh Carlson
Kendall County GIS
Brian_McLeer
Occasional Contributor II

@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}
}

 

Brian
0 Kudos
Brian_McLeer
Occasional Contributor II

Thank you both for your assistance on this, greatly appreciated. 

Brian
0 Kudos