HOW TO

Label a feature layer by truncating the field values with multiple words based on conditions in ArcGIS Pro

Last Published: August 18, 2023

Summary

In ArcGIS Pro, when labeling a feature layer, it is sometimes necessary to truncate a field value with multiple words and only display the first word to avoid cluttering the map. However, in some instances, the first word of the field values is short and cannot be shortened further.

In this article, an Arcade expression is used to truncate fields with multiple words, leaving the first word of the field based on a condition. If the condition is not met, the second word is also displayed in the label on the map.

In this example, the field value in the Company field is truncated when the first word consists of more than three characters. If the first word consists of three characters or less, the second word is also displayed in the label on the map.

Attribute table containing field values with multiple words.

Procedure

  1. Open the ArcGIS Pro project, add the layer, and create a label expression. Refer to Steps 1 through 4 in ArcGIS Pro: Writing a label expression for instructions. Select Arcade for Language.
Note:
In the Contents pane, ensure the selected feature layer and feature class check boxes are checked to display the labels.
  1. Insert and configure the expression below in the Expression box:
var name_parts = Split($feature.<field_name>, ' ')
IIF(Count(name_parts[0]) > <value>, name_parts[0], `${name_parts[0]}\n${name_parts[1]}`)
  1. Replace <field_name> with the name of the field to be truncated. In this example, the field name is Company.
  2. Replace <value> with the minimum number of characters the first word must consist of, otherwise the second word is also displayed. In this example, ‘3’ is the value used in the expression.
  1. Click the Verify button to validate the expression.
  2. Click Apply to run the script.
Label expressione editor window.

The image below displays the truncated labels of field values with multiple words on a map in ArcGIS Pro.

Web map displaying truncated labels.

Article ID: 000029646

Software:
  • ArcGIS Pro 3 1
  • ArcGIS Pro 3 0
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options