Hi,
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.
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