# Is the Intersection Operation Commutative?

In map overlay, is intersection of map layers a commutative operation ie layer_A intersection layer_B = layer_B intersection layer_A? If layer A is a square and layer B is a triangle. In this case, (A intersectn B) == (B intersectn A) ?

Hope this figure is explicit enough : • thanks for the reply, so I should assume A.B = B.A where A and B are two different vector data map layers? – satish puri Jul 17 '11 at 17:02
• the equality you mentionned is correct, see also blord-castillo's answer. – simo Jul 18 '11 at 14:13

Just like set intersection, geometric intersection (which is essentially an intersection on two sets with spatially defined bounds) is both commutative and associative, e.g. (A ∩ B) ∩ C = A ∩ (B ∩ C) = (C ∩ B) ∩ A = C ∩ (B ∩ A).

In practice, software often uses the order of inputs to determine how attributes are associated with the output; but the spatial output geometry should still be the same regardless of input order.

Also be aware that your output will depend on which coordinate system and projection, if any, you use to carry out the operation. While this will not change the commutative and associate properties, order and grouping might be used to select the projection used for the operation(s).

• I haven't tried it lately, but with ArcGIS I recall that that the order of arguments for intersect matters if the XY domain (xy precision) of the layers involved differ - even though the spatial references were the same. – Kirk Kuykendall Jul 18 '11 at 3:13

Mmmm. I too thought it obvious that A ∩ B = B ∩ A, but then Kirk's comment got me thinking. So here's a theory. Feel free to shoot it down in flames!

In this scenario there are two polygons, A (red) and B (blue). The red dots represent the smallest grid precision: According to my calculations, they intersect here: Notice how the intersection point snaps to the nearest grid, because that's the smallest precision allowed. In this case the order doesn't matter, and A ∩ B = B ∩ A

Now introduce polygon C (yellow): The intersection of (A ∩ B) ∩ C is as follows: And that's because the nearest grid point to the intersection of A and B is as already shown, and overlaid with C is can give that result (my rough sketch is not exactly square so it may not look obvious at a glance). However, (A ∩ C) ∩ B gives this: That's because the nearest grid to the intersection of A and C causes a different shape for the intersection with B.

So: I would argue that there is no difference with just two polygons, but there could be differences with three or more. With a large precision the differences would be tiny, but I believe they could exist.

Does that look correct, or can anyone pick holes in the concept?!?!?!

• That would still be a software dependent issue though. You could just as easily store the result as a vector function intermediate until all intersections are completed and then convert the vector input to the spatial precision when done as well. The actual theory behind the operation has the operation associative and commutative. – blord-castillo Jul 25 '11 at 15:22
• Or to take that to a different context, consider a computer that stores numbers only out to 5 decimal places. 4 * 0.1 * 0.00005 should be 0.00002 in theory, whether done as (4 * 0.1) * 0.00005 or as (0.1 * 0.00005) * 4. But when carried on on this computer, (4 * 0.1) * 0.00005 = 0.4 * 0.00005 = 0.00002 but (0.1 * 0.00005) * 4 = 0.00001 * 4 = 0.00004 (or it is equal to 0.00000 * 4 = 0 depending on how rounding is handled). The result would imply that multiplication is not associative or commutative, but the result is really just an artifact of the computation method. – blord-castillo Jul 25 '11 at 15:25