Arcade popup calculations on cascading intersections

330
1
03-16-2021 01:34 PM
Labels (1)
DavidHood_USFS
New Contributor III

What I want to do:

When I click on a project boundary I want to return the Lynx Analysis Units (LAU) that intersect the project boundary.  Then I want to take each of those intersecting LAU’s and calculate the acres of Lynx Habitat broken out by the Structural Stage (field = ‘StructuralStage’) within that entire LAU.

Below is what I’ve started with and I’m close, just can’t figure out what I need to change.  Currently I’m only getting the Structural Stage information for the first LAU.  I would also like to clean up the number formatting to '#,###.#' and add “acres “.  I'm assuming its how I'm compiling the information at the end, but I'm not sure what I need to change as I'm still learning how to use Arcade.

var int_LAUs = Intersects($feature, FeatureSetByName($map,"LynxAnalysisUnits"));

var LynxHabitat = FeatureSetByName($map,"Lynx Habitat - Structural Stages");

var LAU = {}
var ss = {}
var xs = 0
var LH_area = 0

for (var i in int_LAUs){
    var xs = AreaGeodetic(i, 'acres')
    var int_lh = Intersects(i, LynxHabitat)
    if(HasKey(LAU, i.DRAINAGE)){
        LAU[i.DRAINAGE] += xs
    }else{
        LAU[i.DRAINAGE] = xs
    }}
    for (var h in int_lh){
        var lh_area = AreaGeodetic(Intersection(i,h), 'acres')
        if(HasKey(ss, h.StructuralStage)){
            ss[h.StructuralStage] += lh_area
        }else{
            ss[h.StructuralStage] = lh_area
        }
        }
    

var out_str = "Lynx Structural Stage"

for (var d in LAU){
    out_str += '\n' + d + ' LAU: ' + Text(LAU[d], '#,###.#' + ' acres') +'\n' + Text(ss, '#,###.#' + ' acres') 

}

return out_str

 

Screen capture of what my current arcade script is providing.

DavidHood2_0-1615924711708.png

 

0 Kudos
1 Reply
jcarlson
MVP Esteemed Contributor

In line 31 of the code you posted, you're telling it to return the text of ss, which is a dictionary, so that's why you're getting the output you're seeing.

You'll need to iterate over the ss dictionary similarly to how you're going over each item in LAU. Looking at your output, the output of ss is the same for each. I'm assuming, though, that this is not what you're trying to do, but that you'd want the ss values specific to each LAU?

I also notice that in spite of you indentations, your two for-loops are independent of one another. I think you want them nested?

- Josh Carlson
Kendall County GIS
0 Kudos