Frequency using Arcade

523
4
06-16-2021 04:46 AM
AJohns17
New Contributor II

I'm looking to get the frequency of points within 2 polygons in my map's pop ups. 

points -> poles

polygon 1 -> inspection grids (filtering on inspection year)

polygon 2 -> municipalities

set up: Our engineering group would like to compare the number of poles to be inspected with the completed inspections.  Poles are inspected by grids, but they need the count within the municipality for permitting.  I have been able to get the count of poles in each grid and the count of poles in each municipality, but I can't seem to figure out how to get the count of poles to be inspected (in the grids) by municipality.

In ArcMap/Pro, I would complete this task by the following workflow:

-Select by Location: select poles within the grids (this produces the poles to be inspected)

-Spatial Join: the selected poles to be inspected within the municipalities

-Frequency: the number of poles to be inspected in each municipality

 

current expression being used to get the count of poles by muni:

var poles = FeatureSetByName($map,"Poles")
var polesInMuni = Count(Intersects(poles,$feature))

return polesInMuni

 

I attached a snip of a highlighted muni, let's call it "Home".  the blue dots that fall within Home and the 2 overlapping grids are the ones I need to count.

 

 

Tags (2)
0 Kudos
4 Replies
jcarlson
MVP Notable Contributor

It gets a bit complicated with two polygon layers, but however you do it, you'll need to run a few more things in the expression. Unfortunately, you can't run Intersects between two FeatureSets, so we'll need to use a loop.

  1. Intersect poles w/ clicked polygon
  2. Intersect clicked polygon w/ second polygon layer
  3. For each intersected second polygon, get the subset of intersected points
  4. Aggregate results from 3

 

var poles = FeatureSetByName($map, "Poles")
var grids = FeatureSetByName($map, "Inspection Grid")

var xs_pts = Intersects(poles, $feature)
var xs_grid = Intersects(grids, $feature)

var out_count = 0

for (var g in xs_grid){
    var sub_count = Count(Intersects(xs_pts, g))
    Console(`${sub_count} in ${g}`)
    out_count += sub_count
}

return out_count

 

Here's a sample running against US states, cities, and a scratch layer:

jcarlson_0-1623849355930.pngjcarlson_1-1623849370644.png

 

If you wanted a per-grid breakdown, that's doable as well, but this will work for a simple count.

- Josh Carlson
Kendall County GIS
AJohns17
New Contributor II

thanks @jcarlson but it's not working properly.  after plugging in my data, I get a number but the count doesn't match what I get in ArcMap using the previously mentioned process.

AJohns17_2-1623855687816.png

 

AJohns17_0-1623855629220.png

 

0 Kudos
jcarlson
MVP Notable Contributor

Have you done a visual count to verify what the number is supposed to be? Also, note that using $feature in Arcade may produce inaccurate results depending on the scale of your map and how close intersecting features may be to the edge. Do you get different results at larger/smaller scales?

- Josh Carlson
Kendall County GIS
0 Kudos
AJohns17
New Contributor II

here is a visual of one area:

AJohns17_0-1623859546907.png

the selected line is of a muni boundary, the green is the grid and i added a red dot to each of the poles.  6 are shown but the expression is only reading 5.

0 Kudos