HOW TO
In Map Viewer for ArcGIS Online and ArcGIS Enterprise, calculating the length of line features that intersect with polygon features provides real-time, spatially aware information directly within a map. This calculation helps identify the area covered by the lines, which is useful when avoiding extra segments on the map or performing spatial analysis.
In this article, an Arcade expression is used to calculate the total length of lines that intersect with a polygon feature in Map Viewer.
var lineLayer = FeatureSetByName($map, "<LayerName>", ["*"]); var totalLength = 0;
for (var line in lineLayer) { if (Intersects($feature, line)) { totalLength += Length(line); } }
Round(totalLength, 2)
The code below shows the full working script.
var lineLayer = FeatureSetByName($map, "Roads", ["*"]); var totalLength = 0; for (var line in lineLayer) { if (Intersects($feature, line)) { totalLength += Length(line); } } Round(totalLength, 2)
The Map Viewer pop-up displays the total length of line features intersecting with a polygon feature.
Article ID: 000033444
Get help from ArcGIS experts
Download the Esri Support App