Summary
It is sometimes necessary to calculate and populate the XY coordinate data of the start and end point of a line feature in an attribute table. However, this task is time-consuming if there are many line features in the web map. This task can be automated using an Arcade expression. This article provides the workflow to calculate the XY data of line features into an attribute table using an Arcade expression in Portal for ArcGIS and ArcGIS Online Map Viewer.
Procedure
- Log in to Portal for ArcGIS or ArcGIS Online and click Content > My Content.
- Browse to and click the hosted feature layer to open the item details page.
- Add four new String or Double fields to populate the XY data of the line features. Refer to Portal for ArcGIS: Add a field or ArcGIS Online: Add a field for instructions. The fields are added to populate the values of the start point of the x-coordinate, start point of the y-coordinate, end point of the x-coordinate, and end point of the y-coordinate of the line features.
The following image shows the four newly created fields for the XY coordinates of the start and end points of the line features.
- Configure the XY coordinates of the start point of the line features.
- Click the field header of the start point of the x-coordinate, select Calculate from the drop-down list and click Arcade.
- Copy and paste the following Arcade expression into the Expression box and click Test.
Geometry($feature).paths[0][0].x
- When the Results tab displays the x-coordinate, click OK.
- Repeat Step 4a to Step 4c for the start point of the y-coordinate. Replace 'x' with 'y' from the Arcade expression above.
- Configure the XY coordinates for the end point of the line features.
- Click the field header of the end point of the x-coordinate, select Calculate from the drop-down list and click Arcade.
- Copy and paste the following Arcade expression into the expression box and click Test.
Geometry($feature).paths[-1][-1].x
- When the Results tab displays the x-coordinate, click OK.
- Repeat Step 5a to Step 5c for the end point of the y-coordinate. Replace 'x' with 'y' from the Arcade expression above.
The image below shows the XY coordinates of the start and end points of the line features in the attribute table in Portal for ArcGIS.