Arcade Intersects return greatest overlap of multiple Polygons.

11-29-2023 02:03 PM
Labels (1)
New Contributor


I am having trouble with the intersects function in trying to get it to return the value of the "correct" polygon when two or more are overlapping. Currently I have two polygon layers, one of cells and one of country boundaries. I have my code written down to tell me the country information when a cell is overlapping only one country. But when a cell overlaps with two or more countries I am struggling to find a way to get it to iterate out and choose the one with the greatest overlap. 

This is the code I am as of now working with.

var country = FeatureSetByName($datastore, "Ref_Map", country, true)
var map_intersect = Intersects(country, $feature)
var intcnt = Count(map_intersect)
if intcnt == 0{
result = 'Global'
for (var contry_code in map_intersect){
var result = contry_code.genc3}
return result
0 Kudos
1 Reply
MVP Esteemed Contributor

Depending on the number of features intersected, the expression could take time to evaluate, but if it's just a couple, it shouldn't be so bad.

When you iterate over the intersected countries, just calculate the area of the intersection and if it's the biggest result so far, assign it to the output. If it's smaller, it leaves the output alone.

} else {
var largest = 0

for (var country_code in map_intersect) {
  var xs = Intersection($feature, country_code)
  if (Area(xs) > largest) {
    largest = Area(xs)
    result = country_code.genc3

return result


- Josh Carlson
Kendall County GIS
0 Kudos