Topological Spatial Relationships

alt

Our thesis team at Hack Reactor have begun work on automated air traffic control software. It is an ambitious undertaking, and we would be doomed to underacheive if it wasn't for Postgres and the spatial relationship operators provided with the PostGIS extension.

While PostGIS provides some spatial relationships for 3D geometries, I'm only going to be covering the 2D (and 2.5D) relationships. The geometries covered by most 2D spatial relationship operators are points, polylines, and polygons (and maybe the 'multi' versions of those geometries). While the spatial relationships are 2D and only operate in the x-y domain, the geometries themselves can have z-values and those z's will be ingnored (although beware of vertical lines as those can be tricky).

What can't I do with spatial relationships

If a spatial relationship operator doesn't support testing geometries of certain type, then you may get unexpected behavior. You may think that you can test for 2 polygons for cross, but that relationship is better described by overlaps. If you use a crosses test on 2 polygons, then you may get a false when in fact the 2 polygons do overlap. Beware of false results from spatial operators on unsupported geometries.

  • test point cross point
  • test polygon cross polygon
  • test overlap between geometries of a different types
  • test touches between points
  • there are others I'm probably forgetting or that different libraries don't support

The operators typically available in a geometry library are intersects, disjoint, touches, overlaps, crosses, within and contain. Next Blog I'll focus on the intersect and disjoint operators.