Greetings,
I am new to Arcade, but found it was very useful and opening new ways we perfom spatial analysis and presented in the ArcGIS Online.
I am trying to create an expression to calculate and display Bearing/Azimuth (in degree) between two polygons in the ArcGIS Online pop-ups.
My scenario as below:
Polygon 1 = Land Parcel (Deeds)
Polygon 2 = Pipeline Corridor
I want to calculate bearing/Azimuth from Land Parcel to the nearest pipeline corridor and display on the attribute table when I click to any Land Parcel in the WebMap. Anyone have experience and create expression in Arcade before. Appreciate to share that.
Thanks
You can get something pretty close with Arcade, but the reliability of the output will really depend on your input polygons.
There is a Distance function in Arcade: https://developers.arcgis.com/arcade/function-reference/geometry_functions/#distance
But it assumes you already know which features you're putting into the function. You want to find the nearest one. You could try something like this:
var f1 = $feature // this is your land parcel
var corridors = FeatureSetByName($map, 'pipelines')
var f1_buff = Buffer($feature, 2, 'miles') // adjust distance and units as needed
// get corridors within buffer
var near_corridors = Intersects(f1_buff, corridors)
// empty object to hold nearest feature
var nearest = {
feature: '',
distance: infinity
}
// loop over corridors
for (var c in near_corridors) {
// check distance with parcel
var dist = Distance(f1, c)
// if the distance is smaller than the current nearest feature, swap it in
if (dist < nearest['distance']) {
nearest = {
feature: c,
distance: dist
}
}
}
This only gets you the nearest feature and its distance, though. You want the bearing. The Bearing function in Arcade requires point inputs. You could take the centroid of each feature for a general bearing, if that's all you need.
var near_bearing = Bearing(
Centroid(f1),
Centroid(nearest['feature'])
)
return near_bearing
If you wanted the bearing of the shortest line between the two features, you're getting into trickier stuff, and Arcade probably isn't your best bet.
Thanks @jcarlson
Do I need to merge 2nd expression with one? Or create new?