ST_Crosses function

The ST_Crosses function takes two geometries as input parameters and returns 1 if the first geometry crosses the second. Otherwise, 0 (zero) is returned.

If the second geometry is not represented in the same spatial reference system as the first geometry, it will be converted to the other spatial reference system.

If the first geometry is a polygon or a multipolygon, or if the second geometry is a point or multipoint, or if any of the geometries is null value or is empty, then null is returned. If the intersection of the two geometries results in a geometry that has a dimension that is one less than the maximum dimension of the two specified geometries, and if the resulting geometry is not equal any of the two specified geometries, then 1 is returned. Otherwise, the result is 0 (zero).

Syntax

Read syntax diagramSkip visual syntax diagramST_Crosses(geometry1, geometry2)

Parameter

geometry1
A value of type ST_Geometry or one of its subtypes that represents the geometry that is to be tested for crossing geometry2.
geometry2
A value of type ST_Geometry or one of its subtypes that represents the geometry that is to be tested to determine if it is crossed by geometry1.

Return Type

INTEGER

Example

This code determines if the constructed geometries cross each other.

CREATE TABLE sample_geoms (id INTEGER, geometry ST_Geometry)

INSERT INTO sample_geoms VALUES
       (1, ST_Geometry('polygon((30 30, 30 50, 50 50, 50 30, 30 30))' ,0))

INSERT INTO sample_geoms VALUES
       (2, ST_Geometry('linestring(40 50, 50 40)' ,0))

INSERT INTO sample_geoms VALUES
       (3, ST_Geometry('linestring(20 20, 60 60)' ,0))

SELECT a.id, b.id, ST_Crosses(a.geometry, b.geometry) Crosses
FROM   sample_geoms a, sample_geoms b order by crosses


Results:

ID          ID          CROSSES
----------- ----------- -----------
          2           1           0
          2           2           0
          3           3           0
          2           3           1
          3           1           1
          3           2           1
          1           1           -
          1           2           -
          1           3           -