Write Arcade expressions for symbology and labeling

获得 Aviation Charting 许可后可用。

After configuring your cartographic and aviation annotation feature classes, you can use ArcGIS Arcade to create custom symbology and labels for your 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, though it differs in a few key areas that are explored later in this topic.

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 your Visual Basic scripts, albeit with a different syntax. There are several ways to filter your data similar to how SQL expressions filtered data in ArcMap. You can use extraction queries to filter your data using a set of defined rules. ArcGIS Pro also allows you to set definition queries, which allow you to group features based on their attributes. Further, the Prepare Aviation Data tool allows you to migrate specific attributes from your main features to their respective cartographic features. This topic will exclusively demonstrate the Prepare Aviation Data tool as a replacement for the SQL expressions in ArcMap.

Parsing 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> <> ||, where 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 that help you parse the data coming from the Prepare Aviation Data tool.

注:

You can find the sample Arcade expressions at the following location on your computer: <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 sample Arcade expression in the Aviation Charting product files titled adhp_c_label_arcade_icao.lxp. Open the .lxp file in a plain text editor (such as Notepad++). You'll notice that 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 your cartographic features against 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 guides on 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 critical for becoming productive with Aviation Charting. Arcade is a powerful tool that allows you to make highly customized and repeatable charting configurations. To demonstrate this capability, consider the following 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 your area of interest.

注:

It is assumed that you have already 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 labels on your cartographic feature classes and to create an annotation feature class. While Arcade is not required to create labels or label classes, but it can be helpful for creating labels with attributes on advanced configurations. Based on our example, use the following Arcade expression to label the ADHP_C feature class with an ICAO code from the main ADHP feature class.

The following code sample properly labels the ADHP_C feature class with the ICAO airport code for all aerodromes in your 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 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

Arcade for symbology

In addition to label classes, you can use Arcade to create symbology classes for your features. An Arcade expression allows you to logically separate features using their attributes. Based on our example, use the following Arcade expression to create symbol classes for the ADHP_C feature class.

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 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:

The ADHP_C feature class symbolized by type code