Arcade: Create Filter On Buffer & Intersect of Feature

1151
5
Jump to solution
05-05-2022 09:37 AM
ArmstKP
Occasional Contributor III

I have a bench layer for example.  Two of the fields are {Park_Name} and {condition_score}

I am trying to write an expression that shows me the average bench score in the park, where I clicked on that bench.

I at least have this built so far:

var benchBuff = Buffer($feature, 3000, 'foot')

var benchWithin = Intersects(benchBuff, $layer)

return Round(Average(benchWithin, "condition_score"), 1)

 

I am just not sure how or where to include the {Park_Name} filter and/or sql variable in the expression?

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

You just need the output limited to benches in the same park? You can filter the layer earlier in the expression by attribute, and then use those filtered features in your Intersects function

var park_benches = Filter($layer, `Park_Name = '${$feature['Park_Name']}'`)

var benchBuff = Buffer($feature, 3000, 'foot')

var benchWithin = Intersects(benchBuff, park_benches)

return Round(Average(benchWithin, "condition_score"), 1)

 

- Josh Carlson
Kendall County GIS

View solution in original post

5 Replies
jcarlson
MVP Esteemed Contributor

You just need the output limited to benches in the same park? You can filter the layer earlier in the expression by attribute, and then use those filtered features in your Intersects function

var park_benches = Filter($layer, `Park_Name = '${$feature['Park_Name']}'`)

var benchBuff = Buffer($feature, 3000, 'foot')

var benchWithin = Intersects(benchBuff, park_benches)

return Round(Average(benchWithin, "condition_score"), 1)

 

- Josh Carlson
Kendall County GIS
ArmstKP
Occasional Contributor III

Thank you very much Josh!

I have a question about two of the characters I have pictured below.  What are these?

ArmstKP_0-1651773719917.png

 

0 Kudos
jcarlson
MVP Esteemed Contributor

Ah, those are called backticks. You use them in Arcade (and other programming languages)  to create template literals.

Suppose you had two variables you wanted to pipe into some text. You could just concatenate the text like this:

var x = 'something'
var y = 'something else'

'Variable x is ' + x + ', and variable y is ' + y + '.'

returns:

'Variable x is something, and variable y is something else.'

But a template literal inserts the variables directly into the string.

`Variable x is ${x}, and variable y is ${y}.`

 

Both work, but I personally prefer the backtick style, as I find it easier to use and visualize the resulting string.

- Josh Carlson
Kendall County GIS
0 Kudos
ArmstKP
Occasional Contributor III

Thanks for that info, didn't know!

 

0 Kudos
KimGarbade
Occasional Contributor III

I know this post isn't "fresh", but I wanted to thank you for that first line of code in the solution. Fantastic!  I knew I had used an attribute of $feature in a filter before, but I couldn't remember the syntax and finding it online is close to impossible...maybe I'm Google search challenged.  Finally, I tripped over it here (probably where I stole it from the first time I did it).  Man, could Esri have come up with a more convoluted syntax?...  Tildes, single quotes, 2 dollar signs, and every kind of bracket....Yikes.  Thank you for figuring this out for all of us.

0 Kudos