This topic describes the ST_Crosses function. This function checks whether two geometry objects partially intersect but one does not lie inside the other. If the two geometry objects partially intersect but one does not lie inside the other, this function returns True. Otherwise, this function returns False.

Syntax

boolean  ST_Crosses(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

  • This function returns True only when the intersection of the geometry objects that you specify is not an empty set and has a dimension that is smaller than the maximum dimension among the geometry objects.
  • This function returns True only when the intersection of two geometry objects that you specify is not equal to one of the geometry objects.
  • The geometry objects that you specify must use one of the following DE-9IM matrix patterns:
    • T*T******: This pattern is used when you specify a point and a line, a point and an area, or a line and an area.
    • T*****T**: This pattern is used when you specify a line and a point, an area and a point, or an area and a line.
    • 0********: This pattern is used when you specify two lines.
  • 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 indexes, we recommend that you use the _ST_Crosses function.

Examples

  • Compare two geometry objects by using the default parameter settings.
    SELECT ST_Crosses('LINESTRING(0 0,3 3)'::geometry,'LINESTRING(0 1,1 0)'::geometry);
     st_crosses
    ------------
     t
    (1 row)
                        
  • Compare two geometry objects that overlap.
     SELECT ST_Crosses('LINESTRING(0 0,3 3)'::geometry,'LINESTRING(0 0,1 1)'::geometry);
     st_crosses
    ------------
     f
    (1 row)
                        
  • Compare two geometry objects whose intersection has a dimension that is the same as the maximum dimension among the geometry objects.
    SELECT ST_Crosses('LINESTRING(0 0,3 3)'::geometry,'LINESTRING(1 1,4 4)'::geometry);
     st_crosses
    ------------
     f
    (1 row)