Hi,
I am unable to figure out how I can format labels using ArcCade or Python.
I have 2 fields (row, col). Row can be empty at some location. I want to show col only. How to setup a condition.
It displays "-col1" when row is empty. My syntax is
$feature.ROW + '-' + $feature.COL
please help!
I think this Arcade label expresion will work if the ROW field has 0 (zero) values in it.
if ($feature.ROW == 0){
return $feature.COL}
else
if ($feature.ROW > 0){
return $feature.NAME + "-" + $feature.ACRES}
Just to make sure I understand your question correctly, I'm going to answer referencing the sample data in the table below. If the expected values are wrong, it might be best for you to share your old label script, so we can match the expected behavior.
TestFeature | Row | Col | Desired Result |
A | 5 | 7 | 5-7 |
B | <Null> | 7 | 7 |
C | 5 | <Null> | 5 |
D | <Null> | <Null> | ERROR: NO VALUES |
Arcade:
var row = $feature.ROW
var col = $feature.COL
// First, see if you have BOTH values
if (!IsEmpty(row) && !IsEmpty(col))
{
return row + '-' + col
}
// If you don't have both, but you DO have a column, return it alone.
else if (!IsEmpty(col))
{
return col
}
// This assumes TestFeature C is valid. If you don't have both, but you DO have a row, return it alone.
else if (!IsEmpty(row))
{
return row
}
// This assumes it's possible to have a case like TestFeature D where both values are missing
else
{
return 'ERROR: NO VALUES'
}
Some notes:
Python 3:
def FindLabel ([ROW], [COL]):
row = [ROW]
col = [COL]
# First, see if you have both values (Test Feature A)
if row is not None and col is not None:
return f'{row}-{col}'
# If you don't have both, see if you have just a column (Test Feature B)
elif col is not None:
return f'{col}'
# If you don't have both, see if you have just a row, assuming that's a valid option. (Test Feature C)
elif row is not None:
return f'{row}'
# If you've reached this point, you don't have either value. (Test Feature D)
else:
return 'ERROR: NO VALUES'
Some notes: