Monday, February 22, 2010

Spatially Equal (III)


Spatially Equal (III)


The previous two blogs handled Spatially Equal.

What does Spatially Equal mean? OGC says: Given two (topologically closed) geometric objects “a” and “b”: a.Equals(b) ⇔ a ⊆ b AND b ⊆ a

This means: a is a subset of b and b is subset of a. This can only be true if a and b are equal. OGC continues with the so-called Dimensionally Extended 9 Intersection Matrix (DE9IM). We skip the formal definition here, the essention OGC is describing for Spatially Equal is:

  • there is overlap in their interiors
  • there is overlap in their boundaries
  • there is no overlap of boundary of a and interior of b and vice versa
  • there is no overlap of boundary of a with the exterior of b and vice versa
All these conditions together can only be true if a and b are equal.

A point? A point does not have a real interior (though that can be discussed - what is the interior...), and does not have a boundary. But two points can certainly be equal... So the DE9IM specified by OGC (in summary: "TFFFTFFFT") is not correct for points. Checking this using PostGIS indeed shows that points do have another DE9IM ("0FFFFFF2"), not matching in place 5 (all other places not F, false match with T, true).

PostGIS defines Spatially Equal as: Returns true if the given geometries represent the same geometry. Directionality is ignored. So this last part is important, a clockwise polygon is equal to a counter clockwise polygon, according to PostGIS. It continues: This function will return false if either geometry is invalid even if they are binary equal.. It is a bit unclear if this is relevant for ST_Equals or for the also described ST_OrderingEquals, because we have seen before that PostGIS returns true for invalid but Spatially Equal polygons.

So let's try to make a new definition:

Spatially Equals is:

Alternative 1) two geometries cover the same area. This is an easy one. Too easy.

Alternative 2) both interiors contain the same pointset, and both boundaries contain the same pointset. Not bad.

Alternative 3) same as 2, but to adding: the order of which points are stored in boundaries of a geometry is not relevant

However, I doubt that this addition of 3) is wise. Are two polygons with mutually reversed borders spatially equal? We come back to that in a next blog.

So our current definition is: both interiors contain the same pointset, and both boundaries (if any) contain the same pointset. In this definition a point contains of an interior with a pointset of one element: the point... It might be refined later on.