HOW TO
At times, it is necessary to determine the distance of the nearest point feature from a different point hosted feature layer. For example, the image below shows shopping malls (represented by the purple point features) and train stations (represented by the yellow point features) in a map. The distance from the train station to the shopping mall is determined to inform the public transport users who may opt to walk to the shopping mall from the nearest train station. This distance is populated using an Arcade expression and is displayed on the web map pop-up.
Note: For ArcGIS Online, in the Pop-ups pane, click Attribute expressions > Add expression.
var fs = FeatureSetByName($map,"<Point_Layer_2>"); var buf = Buffer($feature, <value>, "<the unit of measurement>"); var fs_filtered = Intersects(fs, buf); var cnt = Count(fs_filtered); var min_dist = 999;
if (cnt > 0) { for (var f in fs_filtered) { var dist = Distance($feature, f); if (dist < min_dist) { min_dist = dist; } } } return min_dist;
The following code block demonstrates the full Arcade expression.
var fs = FeatureSetByName($map,"PointFeature2"); var buf = Buffer($feature, 400, "meter"); var fs_filtered = Intersects(fs, buf); var cnt = Count(fs_filtered); var min_dist = 999; if (cnt > 0) { for (var f in fs_filtered) { var dist = Distance($feature, f); if (dist < min_dist) { min_dist = dist; } } } return min_dist;
Note: For ArcGIS Online, after copying and pasting the Arcade expression in the expression box, click Run.
Note: For ArcGIS Online, when the Output tab displays the distance, click Done.
The image below shows the distance between a shopping mall and the nearest train station is 384.20553.
Article ID: 000029737
Get help from ArcGIS experts
Download the Esri Support App