The ST_Touches() function
The ST_Touches() function returns t
(TRUE)
if none of the points common to both geometries intersect the
interiors of both geometries; otherwise, it returns f
(FALSE).
At least one geometry must be an ST_LineString, ST_Polygon, ST_MultiLineString,
or ST_MultiPolygon.
Syntax
ST_Touches(g1 ST_Geometry, g2 ST_Geometry)
Usage
The results of the spatial relationship of the ST_Touches() function can be understood or verified by comparing the results with a pattern matrix that represents the acceptable values for the DE-9IM. The pattern matrices state that the ST_Touches() function returns TRUE when the interiors of the geometry do not intersect, and the boundary of either geometry intersects the other's interior or boundary.
Interior (b) | Boundary (b) | Exterior (b) | |
---|---|---|---|
Interior (a) | F | T | * |
Boundary (a) | * | * | * |
Exterior (a) | * | * | * |
Interior (b) | Boundary (b) | Exterior (b) | |
---|---|---|---|
Interior (a) | F | * | * |
Boundary (a) | T | * | * |
Exterior (a) | * | * | * |
Interior (b) | Boundary (b) | Exterior (b) | |
---|---|---|---|
Interior (a) | F | * | * |
Boundary (a) | * | T | * |
Exterior (a) | * | * | * |
Return type
BOOLEAN
Example
The GIS technician is asked to provide a list of all sewer lines whose endpoints intersect another sewer line.
CREATE TABLE sewerlines (sewer_id integer,
class integer,
sewer ST_LineString);
SELECT s1.sewer_id, s2.sewer_id
FROM sewerlines s1, sewerlines s2
WHERE ST_Touches(s1.sewer, s2.sewer);