Select to view content in your preferred language

Calculate difference between attributes of two different features?

429
3
10-07-2022 03:47 AM
JasonCyphers
Frequent Contributor

Is it possible to calculate the difference between attributes of two different features, and then display that as either a label or in a pop-up?  Could that be done with an arcade expression?

 

0 Kudos
3 Replies
JohannesLindner
MVP Frequent Contributor

In a label? No. Labels don't allow access to other features or feature sets for performance reasons.

In a popup? Yes.

 

What exactly do you mean by "calculate the difference between features"?

And how would you determine the other feature?


Have a great day!
Johannes
JasonCyphers
Frequent Contributor

Trying to build a flood map that would estimate the water level in a building.

I have a Flood Level polygon (with a water level attribute) and a Building Footprint layer (with an elevation attribute).  I've built a webapp that allows me to filter the Flood Level polygon to show various water levels and a query widget that allows me to select the building within that polygon.  My next goal is to be able to determine what the estimated water level within that building would be (if the flood level I select is 20, and the building's elevation is 18, I'd like to report that the estimated water level in that building would be 2').

Goal of this webapp is for a utility company, so we can select the projected flood stage, identify meters and buildings within the projected flood area, and mitigate damage however we need to (turn off customer meters, sand bag buildings to prevent infiltration of flood waters (if the water level is low enough), etc.)

0 Kudos
JohannesLindner
MVP Frequent Contributor

Something like this?

// load the flood polygons from the map
var flood_polygons = FeatureSetByName($map, "FloodLevelLayer", ["WaterLevel"])

// get the first flood polygon that intersects this building (other will be ignored)
var flood_polygon = First(Intersects(flood_polygons, $feature))

// return a default value if there are no intersecting polygons
if flood_polygon == null) {
    return "not affected by flooding"
}

// return the difference between the polygon's WaterLevel attribute and the $feature's Elevation attribute
return flood_polygon.WaterLevel - $feature.Elevation

Have a great day!
Johannes
0 Kudos