Fork me on GitHub

ST_Touches

Signatures

BOOLEAN ST_Touches(GEOMETRY geomA, GEOMETRY geomB);

Description

Returns true if geomA touches geomB.

Touches means that:

  • geomA and geomB have at least one point in common.
  • The interiors of geomA and geomB do not intersect.
Remarks
  • ST_Touches can only be used to determine the relation between pairs listed here: (POLYGON, POLYGON), (POLYGON, LINESTRING), (POLYGON, POINT), (LINESTRING, LINESTRING) and (LINESTRING, POINT). The relation (POINT, POINT) is excluded.
  • GEOMETRYCOLLECTIONs are not taken into account.
Implements the OpenGIS Simple Features Implementation Specification for SQL version 1.2.1.
This predicate does not yet support spatial indices, but it will in a future release. Use it in conjunction with && operator. See here for more details.

Examples

Cases where ST_Touches is true
SELECT ST_Touches(geomA, geomB) FROM input_table;
-- Answer:    TRUE
geomA POLYGON geomB POLYGON
POLYGON((1 1, 4 1, 4 5, 1 5, 1 1)) POLYGON((4 2, 7 2, 7 6, 4 6, 4 2))

geomA POLYGON geomB LINESTRING
POLYGON((1 1, 4 1, 4 5, 1 5, 1 1)) LINESTRING(2 5, 7 5)

geomA POLYGON geomB POINT
POLYGON((1 1, 4 1, 4 5, 1 5, 1 1)) POINT(4 3)

geomA LINESTRING geomB LINESTRING
LINESTRING(2 1, 5 3, 2 6) LINESTRING(1 3, 3 5)

geomA LINESTRING geomB POINT
LINESTRING(2 1, 5 3, 2 6) POINT(2 6)

geomA POLYGON geomB MULTIPOLYGON
POLYGON((1 1, 4 1, 4 5, 1 5, 1 1)) MULTIPOLYGON(((4 2, 7 2, 7 6, 4 6, 4 2)), ((0 6, 1 6, 1 7, 0 7, 0 6)))

geomA POLYGON geomB MULTILINESTRING
POLYGON((1 1, 4 1, 4 5, 1 5, 1 1)) MULTILINESTRING((2 5, 7 5), (6 1, 6 4))

geomA POLYGON geomB MULTIPOINT
POLYGON((1 1, 4 1, 4 5, 1 5, 1 1)) MULTIPOINT((4 3), (6 2))

geomA POLYGON geomB POLYGON
POLYGON((1 1, 4 1, 4 5, 1 5, 1 1)) POLYGON((4 5, 7 5, 7 6, 4 6, 4 5))

Cases where ST_Touches is false
SELECT ST_Touches(geomA, geomB) FROM input_table;
-- Answer:    FALSE
geomA POLYGON geomB POLYGON
POLYGON((1 1, 4 1, 4 5, 1 5, 1 1)) POLYGON((3 4, 7 4, 7 6, 3 6, 3 4))

See also