This topic describes the ST_Touches function. This function checks whether two geometry objects intersect.

Syntax

boolean  ST_Touches(geometry  g1 , geometry  g2);

Parameters

Parameter Description
g1 The first geometry object that you want to specify.
g2 The second geometry object that you want to specify.

Description

  • If the points at which the two geometry objects that you specify intersect are concentrated and lie in the boundaries of the geometry objects, this function returns True.
  • The intersection between the two geometry objects that you specify meets one of the following DE-9IM conditions:
    • FT*******
    • F**T*****
    • F***T****
  • This function can check the intersection between two areas, between two lines, between a line and an area, between a point and an area, and between a point and a line.
  • This function cannot check the intersection between two points.
  • This function does not support GeometryCollection objects.
  • This function generates a bounding box, which allows you to use the indexes that are available on the geometry objects that you specify. If you do not want to use the indexes, we recommend that you use the _ST_Touches function.

Examples

  • SELECT ST_Touches('LINESTRING(0 0,0 2)'::geometry, 'LINESTRING(0 2,0 3)'::geometry);
     st_touches
    ------------
     t
    (1 row)
                        
  • Obtain an intersection that does not meet one of the DE-9IM conditions.
    SELECT ST_Touches(g1,g2), ST_Relate(g1,g2) FROM (SELECT 'LINESTRING(0 0,0 2)'::geometry as g1, 'LINESTRING(0 1,0 3)'::geometry as g2) as test;
     st_touches | st_relate
    ------------+-----------
     f          | 1010F0102
    (1 row)