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.
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.
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:
If you wanted a per-grid breakdown, that's doable as well, but this will work for a simple count.
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.
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?
here is a visual of one area:
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.