ST_Touches — Tests if two geometries have at least one point in common, but their interiors do not intersect
boolean ST_Touches(geometry
A, geometry
B);
Returns TRUE if A and B intersect,
but their interiors do not intersect. Equivalently, A and B have at least one point in common,
and the common points lie in at least one boundary.
For Point/Point inputs the relationship is always FALSE,
since points do not have a boundary.
In mathematical terms: ST_Touches(A, B) ⇔ (Int(A) ⋂ Int(B) = ∅) ∧ (A ⋂ B ≠ ∅)
This relationship holds if the DE-9IM Intersection Matrix for the two geometries matches one of:
FT*******
F**T*****
F***T****
|
|
|
This function automatically includes a bounding box comparison
that makes use of any spatial indexes that are available on the geometries.
To avoid using an index, use |
Enhanced: 3.0.0 enabled support for GEOMETRYCOLLECTION
This method implements the OGC Simple Features
Implementation Specification for SQL 1.1.
s2.1.1.2 // s2.1.13.3
This method implements the SQL/MM specification.
SQL-MM 3: 5.1.28
The ST_Touches predicate returns TRUE in the following examples.
Two Polygons touching along a boundary segment.
SELECT ST_Touches(a, b) FROM (SELECT 'POLYGON ((10 190,10 70,80 70,80 130,50 160,120 160,120 190,10 190))'::geometry AS a, 'POLYGON ((80 110,140 140,190 110,180 40,140 10,80 50,80 70,80 110))'::geometry AS b ) AS example;
t
Two Polygons touching at a boundary point.
SELECT ST_Touches(a, b) FROM (SELECT 'POLYGON ((10 190,10 70,80 70,80 130,50 160,120 160,120 190,10 190))'::geometry AS a, 'POLYGON ((140 140,190 110,180 40,140 10,80 70,140 140))'::geometry AS b ) AS example;
t
A Polygon and a LineString touching at the line endpoint.
SELECT ST_Touches(a, b) FROM (SELECT 'POLYGON ((80 10,50 40,50 90,80 130,140 120,160 70,140 30,80 10))'::geometry AS a, 'LINESTRING (30 190,180 150,160 70)'::geometry AS b ) AS example;
t
Two LineStrings touching at their endpoints.
SELECT ST_Touches(a, b) FROM (SELECT 'LINESTRING (10 10,60 140,140 190)'::geometry AS a, 'LINESTRING (140 190,190 10)'::geometry AS b ) AS example;
t
Two LineStrings touching where an endpoint meets the other line.
SELECT ST_Touches(a, b) FROM (SELECT 'LINESTRING (10 10,60 140,140 190)'::geometry AS a, 'LINESTRING (60 140,190 10)'::geometry AS b ) AS example;
t
A Point touching a Polygon boundary.
SELECT ST_Touches(a, b) FROM (SELECT 'POLYGON ((30 30,10 110,40 190,120 170,180 180,170 100,130 10,30 30))'::geometry AS a, 'POINT (170 100)'::geometry AS b ) AS example;
t
SELECT ST_Touches('LINESTRING(0 0,1 1,0 2)'::geometry, 'POINT(1 1)'::geometry);
f
SELECT ST_Touches('LINESTRING(0 0,1 1,0 2)'::geometry, 'POINT(0 2)'::geometry);
t