ST_Touches
What is ST_Touches?
ST_Touches is a PostGIS spatial predicate that returns true when two geometries share at least one boundary point but no interior points. This captures the notion of adjacency — polygons that share an edge, or a line whose endpoint lands on another line.
ST_Touches(geometry geomA, geometry geomB) → booleanValid DE-9IM patterns: FT*******, F**T*****, or F***T****. Two points never "touch" in this sense, because points have no boundary.
When would you use ST_Touches?
Use ST_Touches to build adjacency graphs between polygonal regions — neighbouring parcels, countries sharing a border, cells sharing an edge — or to find line segments that meet end-to-end. It is the standard predicate for contiguity analysis in spatial statistics (queen/rook adjacency).
1SELECT a.name, b.name
2FROM countries a
3JOIN countries b ON ST_Touches(a.geom, b.geom)
4WHERE a.name < b.name;FAQs
How is ST_Touches different from ST_Intersects?
ST_Intersects returns true for any shared point, including interior overlaps. ST_Touches specifically excludes interior overlaps — the geometries must meet at their boundaries only. If the interiors meet (even at a single point that is interior to both), the result is false.
Do two points ever touch?
No. Points have no boundary, so ST_Touches(point, point) is always false. Use ST_Equals or ST_DWithin(a, b, tolerance) to test point-to-point proximity instead.
Is ST_Touches useful for building adjacency matrices?
Yes — this is its most common application. For a contiguity weight matrix in spatial econometrics, ST_Touches gives you rook contiguity (shared edge). For queen contiguity (shared edge or corner), ST_Touches still works because a shared corner is also boundary contact.
Is ST_Touches index-accelerated?
Yes. The planner uses the && bounding-box operator against the GiST index to find candidate pairs, then evaluates the full predicate on the shortlist. Always create a GiST index on the geometry column for efficient adjacency queries.