Try something like this:
with_variable(
'B',
overlay_intersects(
'PolyB layer name / id', -- set inside quotes PolyB layer name or id
$geometry
)[0],
area(intersection($geometry, @B)) / area(union($geometry, @B))
)
Answer from Mayo on Stack ExchangeVideos
How do I find the union and intersection of two sets?
To find the union and intersection of two sets, you need to:
- List all elements from the first set.
- Add the elements from the second set.
- Cross out any repetitions (i.e., leave one copy of each).
- For every element, check if it's in the sets:
-
The union gathers those that appear in at least one; and
-
The intersection gathers those that appear in both.
-
- Enjoy having found the union and intersection of two sets.
How do I find the union and intersection of intervals?
To find the union and intersection of two intervals, you need to:
-
Draw the number line.
-
Mark the endpoints of the first interval.
-
Color the line between those points.
-
Mark the endpoints of the second interval.
-
Color the line between those points using a different color.
-
The left endpoint of:
- The union is the leftmost of the left interval endpoints; and
- The intersection is the rightmost of the left interval endpoints.
-
The right endpoint of:
- The union is the rightmost of the right interval endpoints; and
- The intersection is the leftmost of the right interval endpoints.
-
For the intersection, if the left endpoint is larger, the intersection is empty.
-
Mark the endpoints as open or closed, depending on the initial data.
What is the difference between union and intersection?
On the one hand, the union gathers all the elements occurring in at least one of the sets. As such, all of them are its subsets. For example, the union of two sets, with one entirely contained in the other, is equal to the larger one.
On the other hand, the intersection gathers all the elements common to each and every one of the sets. As such, it's a subset of each of them. For instance, the intersection of two sets with one entirely contained in the other is equal to the smaller one.