Abbreviate labels based off feature size

567
8
12-01-2023 06:11 AM
leahmaps
Occasional Contributor II

Hello! 

I have a question about labels based off feature size, using Arcade. 

I am labeling geometries with IDs, first and last names, but due to various sizing, the names do not always fit well. What I want to do is

  • Always label the geometry with the ID
  • If the geometry is too small, abbreviate the first name to the first letter.
  • Always label last name

Is there an arcade expression that would allow for abbreviation on many unique variables while testing against geometry size?

Any help is appreciated!

0 Kudos
8 Replies
ZachBodenner
MVP Regular Contributor

Are you married to Arcade in this scenario? You could just have a couple different label classes and use the SQL query to set restrictions on each class based on feature size. It wouldn't be perfect because the actual shape of your shapes will affect whether or not a label fits, but it would get you close.

0 Kudos
leahmaps
Occasional Contributor II

Not necessarily, but I already have an arcade expression to remove some labels but leave the ID. There is also the case of having a lot of different geometries at different scales. In this case, I am doing a map series which changes scale on every page (sadly) so I am just trying to find the best way to go about this.

0 Kudos
JesseWickizer
Esri Contributor

Turn on abbreviation in the Maplex label engine and use an alternate expression.

JesseWickizer_1-1701800056436.png

Here you can use Arcade to only display the 1st letter of the first name if the label doesn't fit in the available space. This Arcade expression labels with the ID field, the first character of the FirstName field, and the LastName field:

$feature.ID + " " + $feature.FirstName[0] + " " + $feature.LastName

Using this approach yields the following results when this abbreviation is used:

  • There is room for the 6 LeBron James label to fit so abbreviation is not used.
  • The 23 Michael Jordan label does not fit so it is abbreviated to 23 M Jordan.
  • Even with abbreviation, 34 Giannis Antetokounmpo does not fit so the label cannot be placed (the "View Unplaced" setting is turned on to draw unplaced labels in red).

JesseWickizer_0-1701799551179.png

 

 

0 Kudos
leahmaps
Occasional Contributor II

Hello!

Just getting back to this. For the most part, it worked but there are still some labels that should be abbreviated that are not. 

Divided row did not abbreviateDivided row did not abbreviate

I attached one sample of areas that are not abbreviated. As you can see, the top box, 11-H-04-0 did abbreviate the first name due to size. The boxes below it, although the names and ID do not fit, did not abbreviate. Because of this, they are overlapping and not readable. 

While most of the areas are fine, there are still some instances where this is happening. Any idea of how to force these to abbreviate?

 

 

0 Kudos
JesseWickizer
Esri Contributor

I have some questions that might help identify why these aren't abbreviating.
Are all labels in this example from the same label class?
What is your label expression and what is the abbreviation alternate expression?
What version of Pro are you using?

0 Kudos
leahmaps
Occasional Contributor II

Hello Jesse, here are the answers!

- Yes, all labels in this map are from the same feature class and label class

- Here is the label expression I am using (written in Arcade)

 

 

 

var lotID = $feature.CemID
var fName = IIf($feature.OwnFirst != 'City', $feature.OwnFirst, '')
var lName = IIf($feature.OwnLast != 'City Hold', $feature.OwnLast, '')

return lotID + TextFormatting.NewLine + "<FNT name = 'Calibri' style = 'Regular' size = '4'>" + Replace(fname, '&', '&amp;') + ' ' + lName + "</FNT>"

 

 

 

 

- And the Abbreviation Strategy I am using (also in Arcade)

 

 

 

$feature.CemID + TextFormatting.NewLine + $feature.OwnFirst[0] + " " + $feature.OwnLast

 

 

 

 

- My version of Pro is 3.2.0

 

Thanks in advance for any help!

 

(editing this after my initial post)

Sometimes it works, sometimes it doesn't for the smaller features, here is an example the abbreviation strategy working as expected when everything doesn't fit. 

leahmaps_0-1704720384660.png

 

0 Kudos
leahmaps
Occasional Contributor II

Interesting new thing as of today @JesseWickizer. Now, when there is a name of City City hold, it is ignoring the IIf statement and still abbreviating them to "C City Hold" I am not sure if it is something coming from the label or abbreviation, but it now acts weird!

0 Kudos
JesseWickizer
Esri Contributor

You should put the same checks for $feature.OwnFirst != 'City' and $feature.OwnLast != 'City Hold' in the alternate expression. For example:

var lotID = $feature.CemID
var fName = IIf(Lower($feature.OwnFirst) != 'city', $feature.OwnFirst, '')
var lName = IIf(Lower($feature.OwnLast) != 'city hold', $feature.OwnLast, '')

var label = lotID;
if (!IsEmpty(fName) && !IsEmpty(lName)){
  label += TextFormatting.NewLine;
  label += "<FNT name = 'Calibri' style = 'Regular' size = '4'>";
  if (!IsEmpty($feature.OwnFirst)) {
    label += $feature.OwnFirst[0] + " ";
  }
  if (!IsEmpty($feature.OwnLast)) {
    label += $feature.OwnLast;
  }
  label += "</FNT>";
}
return label;

 

0 Kudos