Select to view content in your preferred language

Arcade expresssion (ArcGIS Online) to pop-us Direction/Bearing (degree) between two polygons

494
2
01-16-2024 02:32 AM
Labels (1)
MohdZukhairiAbdLatef
Emerging Contributor

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

 

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

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.

- Josh Carlson
Kendall County GIS
0 Kudos
MohdZukhairiAbdLatef
Emerging Contributor

Thanks @jcarlson

Do I need to merge 2nd expression with one? Or create new? 

0 Kudos