Write Arcade expressions for symbology and labeling

Available with Aviation Charting license.

After configuring cartographic and aviation annotation feature classes, you can use ArcGIS Arcade to create custom symbology and labels for the aeronautical data. Arcade expressions allow you to extract attributes from a feature class and use that feature's attributes to change its symbology and labels. The following sections describe the best practices for writing Arcade expressions with ArcGIS Aviation Charting.

Arcade

Arcade is a programming language developed by Esri that is used to write expressions for labeling and symbology. Arcade has a number of other uses that are not covered in this topic including field calculation and drawing geometry. The syntax of Arcade is most similar to JavaScript, but it differs in a few key areas that are explored below.

Learn more about Arcade

If you are a user coming to ArcGIS Pro from ArcMap, you may be familiar with configuring VST rules with Visual Basic and SQL expressions. You can use Arcade to replicate the same logic you configured in Visual Basic scripts, but with a different syntax. There are several ways to filter data similar to how SQL expressions filtered data in ArcMap. You can use extraction queries to filter data using a set of defined rules. ArcGIS Pro also allows you to set definition queries to group features based on their attributes. You can also use the Prepare Aviation Data tool to migrate specific attributes from main features to their respective cartographic features. Using the Prepare Aviation Data tool as a replacement for the SQL expressions in ArcMap is described below.

Parse the output from the Prepare Aviation Data tool with Arcade

The Prepare Aviation Data tool migrates attributes from main aviation data to their respective cartographic features. This tool outputs attributes to a field on the cartographic feature class in a specific format. The format is || <> <value> <> || in which features are delimited by || and the attribute values of those features are delimited by <>. This represents a one-to-many relationship between the field in the cartographic feature class and the fields in the main feature class.

The Aviation Charting product files package contains sample Arcade expressions you can use to parse the data from the Prepare Aviation Data tool.

Note:

Sample Arcade expressions are available on your computer at <installation location>/SampleConfigs/ICAO/Enroute/ArcadeExpressions. The default installation location for the Aviation Charting product files is C:/Users/Public/Documents/ArcGIS Aviation Charting/Product Files/<version>/.

Browse to the adhp_c_label_arcade_icao.lxp sample Arcade expression in the Aviation Charting product files. Open the .lxp file in a plain text editor (such as Notepad++). There is a function definition near the top of this Arcade expression file called GetFeaturesArray. The GetFeaturesArray function takes two arguments:

  • stringVal—The name of the field in the cartographic feature class that contains the output from the Prepare Aviation Data tool.
  • fieldNameArray—The name of the fields that is derived by this function from the field in the cartographic feature class.

The GetFeaturesArray function processes cartographic features using these arguments and returns a dictionary of key-value pairs representing the derived field and its value.

Consider the following code sample:



var mainFieldArray = ["name_txt", "type_code"]
var mainArray = GetFeaturesArray($feature.Main_Info, mainFieldArray)

In this example, there are two variable declarations: mainFieldArray and mainArray. The mainFieldArray variable contains an array of strings for each field to be derived from the cartographic feature class. The mainArray variable is, inherently, a dictionary since it is set equal to the value returned from the GetFeaturesArray function. The GetFeaturesArray function accepts two arguments: $feature.Main_Info (representing the name of the field in the cartographic feature class from which attributes are parsed) and mainFieldArray. The next section explains how to access data from this dictionary to create labels and symbology.

Understand how to use Arcade for aeronautical charts

Understanding how to read and write Arcade expressions is essential for becoming productive with Aviation Charting. Using Arcade, you can make customized and repeatable charting configurations. The following is an example:

You want to symbolize and create labels on the ADHP_C feature class to visually differentiate between aerodromes and heliports and show the ICAO airport code for all aerodromes in the area of interest.

Note:

It is assumed that you used the Prepare Aviation Data tool to migrate the name_txt and type_code fields to the ADHP_C cartographic feature class.

Arcade for labeling

You can use Arcade to create label expressions on the cartographic feature classes or feature-linked annotation feature class's annotation class. While writing Arcade expressions is not required to customize labels or annotation classes, it can be helpful for creating labels that rely on multiple feature attributes and custom logic.

Based on the example outlined above, the following code sample properly labels the ADHP_C feature class with the ICAO airport code from the main ADHP feature class for all aerodromes in the area of interest, excluding helipads:



// Make sure to put the function declaration for GetFeaturesArray here.

var mainFieldArray = ["name_txt", "type_code"];
var mainArray = GetFeaturesArray($feature.Main_Info, mainFieldArray);

// If there are no features in the dictionary, return with an empty label string.
if (Count(mainArray) == 0) return "";

mainFeature = mainArray[0];
 
// Get the attributes.
// Note that the values in the dictionary are the same that were defined for the mainFieldArray array.
var strName = mainFeature.name_txt;
var typeCode = mainFeature.type_code;

// Generate the output string if the type_code value is 'AD' (aerodrome).
var strOut = "";
if (typeCode == 'AD') {
    
strOut = strName;
} else {
    strOut = "";
}

// Return the output string.
return strOut;

The output of the label expression above appears on the map as shown in this image:

A simple label expression applied to the ADHP_C feature class

Note:

When writing expressions for annotation classes in feature-linked annotation feature classes, Arcade has access to all the attributes from the linked feature class. So, for example, the same Arcade label expression code from a cartographic_C feature class can be copied and reused in an annotation feature class's annotation class, and produce the same label output.

Arcade for labeling with the Aviation Abbreviate command

Arcade label expressions can be written to use the Aviation Abbreviate command in the Annotation tool. For example, when you edit an annotation feature on the map using the Annotation tool Edit Annotation and the Aviation Abbreviate command, you can choose an abbreviation field option. After selecting an option, the Arcade label expression code for that annotation feature triggers the expression code for new label text that outputs based on the chosen abbreviation field option. For this to function, you must do the following:

  • Ensure that the annotation feature class is feature-linked to a backing feature class, such as a cartographic _C feature class.
  • Identify the annotation class from the annotation feature class that you want the Aviation Abbreviate command to be available on.
  • Identify a coded value domain attribute from the backing feature-linked feature class whose domain values are used as the abbreviation field options.
  • Create an Abbreviation Annotation preference for the annotation feature class that associates the annotation class with the abbreviation field.
  • Configure the label expression code to read the abbreviation field. Write custom Arcade logic that outputs different label output based on each of the abbreviation field’s domain values.

The following annotation class label expression code sample shows how label output can be customized based on the abbreviation field’s current option:

//LABELSTATUS_CODE has been configured as the abbreviation field for this annotation class in the Abbreviate Annotation preference. 
// Full Label, No Label, and Abbreviated Label are domain values in LABELSTATUS_CODE 
var statusName = DomainName($feature, "LABELSTATUS_CODE"); 
//The label output is customized 3 ways based on the current domain value of LABELSTATUS_CODE 
var labelOutput = “”; 
if (statusName == “Full Label”){ 
    labelOutput = “custom output 1”; 
} else if (statusName == “No Label”){ 
    labelOutput = “custom output 2”; 
} else if (statusName == “Abbreviated Label”){ 
    labelOutput = “custom output 3”; 
} 
return labelOutput;

Arcade for symbology

In addition to label classes, you can use Arcade to create symbology classes for features. An Arcade expression allows you to logically separate features using their attributes.

Based on the example outlined above, the following code sample creates symbol classes for the ADHP_C feature class using its type_code attribute:



// Make sure to put the function declaration for GetFeaturesArray here.

var mainFieldArray = ["name_txt", "type_code"];
var mainArray = GetFeaturesArray($feature.Main_Info, mainFieldArray);

// If there are no features in the dictionary, return with an empty label string.
if (Count(mainArray) == 0) return "";

mainFeature = mainArray[0];
 
// Get the attributes.
// Note that the values in the dictionary are the same that were defined for the mainFieldArray array.
var strName = mainFeature.name_txt;
var typeCode = mainFeature.type_code;

// Return the type_code of the feature.
// "AD" -> Aerodrome.
// "HP" -> Heliport.
var outputSymbolClass = "";

if (typeCode == "AD") {
	outputSymbolClass = "Airport";
} else if (typeCode == "HP") {
	outputSymbolClass = "Heliport";
}

return outputSymbolClass;

The output of the symbol class expression above appears on the map as shown in this image:

ADHP_C feature class symbolized by type code