Select to view content in your preferred language

Complicated Label Expression

345
2
Jump to solution
05-22-2024 01:58 PM
Labels (1)
ElisseDeleissegues1
Occasional Contributor

I have here a new ArcPro Parcel Fabric (3.1.x and PF v5) in an Enterprise environment with Versioned editing.

We have a complicated attribute setup and I am attempting to label these according to the way the editors would like to see them.

Fields: Name, Number, Width, sf, and ac.

We are not using the default StatedArea/StatedAreaUnits fields because our legal descriptions frequently contain both square feet and acres and we want to reflect that in our Tax Map Sheets.

ESMTLabel.jpg

  1.  DRAINAGE AND SEWER ESMT B
  2.  MULTI-USE ESMT 1-B (10 FT WIDE)
  3. ESMT
  4. DRAINAGE ESMT D (4 FT WIDE) *NEWLINE* [260 sf or 0.04 ac]
  5. SEWER AND WATER ESMT (5 FT WIDE) *NEWLINE* [100 sf]
  6. SEWER AND WATER ESMT *NEWLINE* [1.36 ac]

I have 3 separate scripts right now: 1 for Name and Number, 1 for Width, and one for Area.

(See below)

I'm so very close but could use some assistance on combining them into one if possible.

There is also one issue for the Name/Number portion.. I can't figure out how to prevent "<Null>" in the Name.

Esmt_attributes.jpg

Name/Number

var Name = $feature["Name"];
var Number = $feature["Number"];
var label = "";


//Check if Name and Number are empty
if (IsEmpty(Name) && IsEmpty(Number)) {
// If all are empty return ESMT
return "ESMT";
}
else {
// If Name or Number have a value, return their values
if (!IsEmpty(Name)) {
label += Text(Name) + " ESMT";
}
if (!IsEmpty(Number)) {
if (label != "") {
label += " " + Text(Number);
}
}
}

return label

 

Width

var Width = $feature["Width"];
var label = "";

//Check if Width field is empty
if (IsEmpty(Width)){
return label;
} else {
//if Width field is not empty, return value with parentheses and 'FT WIDE'
if (!IsEmpty(Width)){
label = "(" + Text(Width) + " FT WIDE)"
}
}

return label

 

Area

var sf = $feature["sf"];
var ac = $feature["ac"];
var label = "";
Ar
// Check if both sf and ac are empty
if (IsEmpty(sf) && IsEmpty(ac)) {
return label;
} else {
// If either sf or ac have a value, return their values with their respective suffixes
if (!IsEmpty(sf)) {
label += Text(sf, "#,###.##") + " sf";
}
if (!IsEmpty(ac)) {
if (label != "") {
label += " or ";
}
label += Text(ac, "#,###.##") + " ac";
}

}

return "[" + label + "]";

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Is the value literally "<Null>"? Regardless, we can filter for the literal string, too. Be careful that you don't use a function name as a variable, as is the case with Number here.

I like using arrays for complex functions, because they can easily be filtered or concatenated. Looking at the name / number section, it looks like the text "ESMT" always comes after name, or it comes by itself if there is no name. (Is it skipped when there's no name, just a number?)

function NotEmpty(x) { return !IsEmpty(x) && x != '<Null>' }

// name and number, filtered out if empty
var name_num = Filter([
  $feature['Name'],
  'ESMT',
  $feature['Number']
], NotEmpty)

return Concatenate(name_num, ' ')

 

For cases when there's a single condition, as in the Width expression, you can use Iif.

var width_label = Iif(
  NotEmpty($feature['Width'],
  `${$feature['Width']} FT WIDE`,
  Null
)

 

Here it is all together.

function NotEmpty(x) { return !IsEmpty(x) && x != '<Null>' }

// name and number, filtered out if empty
var name_num = Filter([
  $feature['Name'],
  'ESMT',
  $feature['Number']
], NotEmpty)

// join valid attributes with spaces
var name_num_label =  Concatenate(name_num, ' ')

// include "FT WIDE" when width is present, otherwise null
var width_label = Iif(
  NotEmpty($feature['Width']),
  `${$feature['Width']} FT WIDE`,
  null
)

// array of area values, empty values filtered out
var area_arr = Filter([
  Iif(
    NotEmpty($feature['sf']),
    `${Text($feature['sf'], '#,###.##')} sf`,
    null
  ),
  Iif(
    NotEmpty($feature['ac']),
    `${Text($feature['ac'], '#,###.##')} ac`,
    null
  )
], NotEmpty)

// join area values with space and brackets; if no values in area, omit entirely
var area_label = Iif(
  Count(area_arr) > 0,
  `[${Concatenate(area_arr, ' ')}]`,
  null
)

// all labels in single array, filter out empties
var final_arr = Filter([
  name_num_label,
  width_label,
  area_label
], NotEmpty)

// output labels one per line; if <br> doesn't work, try '\n'
return Concatenate(final_arr, '<br>')
- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

Is the value literally "<Null>"? Regardless, we can filter for the literal string, too. Be careful that you don't use a function name as a variable, as is the case with Number here.

I like using arrays for complex functions, because they can easily be filtered or concatenated. Looking at the name / number section, it looks like the text "ESMT" always comes after name, or it comes by itself if there is no name. (Is it skipped when there's no name, just a number?)

function NotEmpty(x) { return !IsEmpty(x) && x != '<Null>' }

// name and number, filtered out if empty
var name_num = Filter([
  $feature['Name'],
  'ESMT',
  $feature['Number']
], NotEmpty)

return Concatenate(name_num, ' ')

 

For cases when there's a single condition, as in the Width expression, you can use Iif.

var width_label = Iif(
  NotEmpty($feature['Width'],
  `${$feature['Width']} FT WIDE`,
  Null
)

 

Here it is all together.

function NotEmpty(x) { return !IsEmpty(x) && x != '<Null>' }

// name and number, filtered out if empty
var name_num = Filter([
  $feature['Name'],
  'ESMT',
  $feature['Number']
], NotEmpty)

// join valid attributes with spaces
var name_num_label =  Concatenate(name_num, ' ')

// include "FT WIDE" when width is present, otherwise null
var width_label = Iif(
  NotEmpty($feature['Width']),
  `${$feature['Width']} FT WIDE`,
  null
)

// array of area values, empty values filtered out
var area_arr = Filter([
  Iif(
    NotEmpty($feature['sf']),
    `${Text($feature['sf'], '#,###.##')} sf`,
    null
  ),
  Iif(
    NotEmpty($feature['ac']),
    `${Text($feature['ac'], '#,###.##')} ac`,
    null
  )
], NotEmpty)

// join area values with space and brackets; if no values in area, omit entirely
var area_label = Iif(
  Count(area_arr) > 0,
  `[${Concatenate(area_arr, ' ')}]`,
  null
)

// all labels in single array, filter out empties
var final_arr = Filter([
  name_num_label,
  width_label,
  area_label
], NotEmpty)

// output labels one per line; if <br> doesn't work, try '\n'
return Concatenate(final_arr, '<br>')
- Josh Carlson
Kendall County GIS
0 Kudos
ElisseDeleissegues1
Occasional Contributor
function NotEmpty(x) { return !IsEmpty(x) && x != '<Null>' }

// name and number, filtered out if empty
var name_num = Filter([
  $feature['Name'],
  'ESMT',
  $feature['Number']
], NotEmpty)

// join valid attributes with spaces
var name_num_label =  Concatenate(name_num, ' ')

// include "FT WIDE" when width is present, otherwise null
var width_label = Iif(
  NotEmpty($feature['Width']),
  `(${$feature['Width']} FT WIDE)`,
  null
)

// array of area values, empty values filtered out
var area_arr = Filter([
  Iif(
    NotEmpty($feature['sf']),
    `${Text($feature['sf'], '#,###.##')} sf`,
    null
  ),
  Iif(
    NotEmpty($feature['ac']),
    `${Text($feature['ac'], '#,###.##')} ac`,
    null
  )
], NotEmpty)

// join area values with space and brackets; if no values in area, omit entirely
var area_label = Iif(
  Count(area_arr) > 0,
  `[${Concatenate(area_arr, ' or ', ' ')}]`,
  null
)

// all labels in single array, filter out empties
var final_arr = Filter([
  name_num_label,
  width_label,
  area_label
], NotEmpty)

// output labels one per line; if <br> doesn't work, try '\n'
return Concatenate(final_arr, '\n')

That's a completely different language! lol

I made a few small changes adding parentheses to `(${$feature['Width']} FT WIDE)`, and "or" to the area concatenation `[${Concatenate(area_arr, ' or ', ' ')}]`,

and this works exactly right!! 😀

This is what my users want to see and I thank you very much

I do wish I was better at these things....but I'm learning👍

0 Kudos