HOW TO

Generate a name field of connected lines between two points using Arcade in ArcGIS Online and Portal for ArcGIS

Last Published: May 3, 2023

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.

The map with labels on each point in ArcGIS Online Map Viewer

Procedure

  1. Open the hosted feature layer’s item details page, and click the Data tab.
  2. Select the line layer to be edited from the Layer drop-down menu. In this example, the testLines layer is selected.
Selecting the layer to be edited
  1. Add a field with a String data type to the layer. Refer to ArcGIS Online: Add a field for more information.
  2. Click the newly created field column, and click Calculate.
  3. In the Calculate Field dialog box, click Arcade.
  4. In the Expression dialog box, insert the appropriate Arcade expression, as described below.
    1. 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>'])
  1. 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)
  1. Identify the intersecting points between the point and line feature.
var ab = Intersects(pole, line)
  1. 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);
  1. Click Test for a preview of the expression result. If the required result is achieved, click OK.
Specifying the Arcade expression in the ArcGIS Online Arcade Calculator window
  1. 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.

The map in ArcGIS Online Map Viewer with the newly configured labels

Article ID: 000030072

Software:
  • ArcGIS Online
  • Portal for ArcGIS

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

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options