Summary
In ArcGIS Online and Portal for ArcGIS, when working in a continuous data collection project, labels can be auto-populated by referencing field values from other layers using Arcade expressions. This article provides an example and instructions to generate a label of connected lines between two points using Arcade in ArcGIS Online and Portal for ArcGIS.
The image below shows a map in ArcGIS Online Map Viewer with labels on each point.
Procedure
- Open the hosted feature layer’s item details page, and click the Data tab.
- Select the line layer to be edited from the Layer drop-down menu. In this example, the testLines layer is selected.
- Add a field with a String data type to the layer. Refer to ArcGIS Online: Add a field for more information.
- Click the newly created field column, and click Calculate.
- In the Calculate Field dialog box, click Arcade.
- In the Expression dialog box, insert the appropriate Arcade expression, as described below.
- Specify the point layer in '<layerName>' and the field name of the point features in '<fieldName>'. In this example, 'testPoints' is used for '<layerName>', and 'Name' is used for '<fieldName>'.
var pole = FeatureSetbyName($datastore, '<layerName>', ['<fieldName>'])
- Create a buffer at a specified distance around the input geometry. In this example, the distance to buffer from the geometry is 0.1.
var line = buffer($feature, .1)
- Identify the intersecting points between the point and line feature.
var ab = Intersects(pole, line)
- Specify the following statement to return the field value which includes the names of the two points of the connecting line, and a separator '-' in between.
var line_name = ''
for (var a in ab){
var pole_name = DomainName(a, 'Name')
line_name += pole_name + " - "}
return left(line_name, count(line_name) -2);
The code block below is an example of the full working expression.
var pole = FeatureSetbyName($datastore, 'testPoints', ['Name'])
var line = buffer($feature, .1)
var ab = Intersects(pole, line)
var line_name = ''
for (var a in ab){
var pole_name = DomainName(a, 'Name')
line_name += pole_name + " - "}
return left(line_name, count(line_name) -2);
- Click Test for a preview of the expression result. If the required result is achieved, click OK.
- Open the hosted feature layer in Map Viewer and apply the labels on the map based on the new field created in Step 3.
The image below shows the newly configured values as label.