Select to view content in your preferred language

Arcade Expression Pop-up help

923
4
Jump to solution
05-16-2022 04:15 AM
Labels (1)
BarryIYoung
Emerging Contributor

Hi, I'm quite new to Arcade Expressions and have created a few simple ones and getting to grips with the basics.  I've currently got an address layer that when a user selects a record it returns information on various intersecting features.  One of these is for school catchments, which works fine, but I'd also like to return associated nursery school data which is stored in a separate table and has a common identifier field which links nurseries with school catchments.

So, basically what I want to return is the intersecting primary school name value from the school catchment boundary (which I've done) and also the nursery schools associated with that same school in the lines underneath.  Expression so far is simply this:

var intersectLayer =Intersects(FeatureSetByName($map,"School Catchment Areas"), $feature)
for (var f in intersectLayer){

return f.name

}

How do I take it a step further to get the associated nursery schools from the separate table?

Thank you.

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Ah, shoot. I left a closing parenthesis off of line 8. I've amended the original expression.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
4 Replies
jcarlson
MVP Esteemed Contributor

What you've got is a good start. In order to other features associated with the intersected boundary, you'll need to interact with that boundary feature directly.

While using a for loop like that does work, it's not the best approach when you know that you've only got a single intersected feature to work with. Consider instead using First, which will take the top record of a FeatureSet and return it as a feature object.

Once you have your catchment, you can use one of its attributes to Filter the associated table. And then once you have the nursery schools, you need some way of taking values out of that FeatureSet and returning them. I've made a few assumptions about layer names and whatnot, but here's what an expression might look like.

 

var catchments = FeatureSetByName($map, 'School Catchment Areas')
var nursery_schools = FeatureSetByName($map, 'Nursery Schools')

// get the first intersecting catchment
var the_catchment = First(Instersects(catchments, $feature))

// filter nursery schools
var matching_schools = Filter(nursery_schools, `catchment_id = '${the_catchment['id']}'`)

// create array of nursery school names
var schools = []

for (var s in matching_schools){
    Push(schools, s['name'])
}

// concatenate array items with newline characters
return Concatenate(schools, '\n')

 

 

- Josh Carlson
Kendall County GIS
BarryIYoung
Emerging Contributor

Thanks Josh, this is really useful.  I've applied the expression using my feature names and field names but I get an error on the var schools = [] line.  Parse Error:Line 11: Unexpected token var

Thanks, Barry

0 Kudos
jcarlson
MVP Esteemed Contributor

Ah, shoot. I left a closing parenthesis off of line 8. I've amended the original expression.

- Josh Carlson
Kendall County GIS
0 Kudos
BarryIYoung
Emerging Contributor

No worries, I should really have noticed that!  That works great - thanks so much 👍

0 Kudos