Summary
In ArcGIS Online, it is possible to calculate the total length of lines within a polygon based on field values and display the results in a pop-up using an Arcade expression. This is useful in understanding spatial relationships and patterns.
In this article, an Arcade expression is used to calculate the total length of the active roads within a neighborhood based on their status, and the result is then displayed in a pop-up. The image below displays the attribute table of the line feature layer representing the roads within the neighborhood.
Procedure
- Open the web map in Map Viewer.
- In the Layers pane, select the layer. In this example, a polygon layer named ‘Neighborhood’ is used.
- On the Settings (light) toolbar, click Pop-ups. Ensure pop-ups are enabled by toggling Enable pop-ups on.
- In the Pop-ups pane, create an Arcade expression to calculate the total length of lines within the polygon layer based on field values. Refer to ArcGIS Online: Use expressions for instructions.
- In the editor window, configure the expression below.
Length(Contains($feature, Filter(FeaturesetByName($datastore, '<feature_name>', ['*']), "<field_name> = '<field_value>'")))
- Replace <feature_name> with the name of the line layer. In this example, ‘Roads’ is used.
- Replace <field_name> with the name of the field containing the field values. In this example, ‘Status’ is used.
- Replace <field_value> with the value of the line features required for the calculation. In this example, ‘Good’ is used.
- Click Done.
- In the Pop-ups pane, click Fields list and click Select fields.
- In the Select fields pane, under Expressions, click the expression created in Step 5 to display in the pop-up.
The image below displays the total length of good roads in the neighborhood in the pop-up in ArcGIS Online.