Skip to main content

st_crosses function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 19 and above check marked yes Lakehouse//RT

note

This feature is not available on Databricks SQL Classic warehouses. To learn more about Databricks SQL warehouses, see SQL warehouse types.

Returns true if the two input GEOMETRY values cross each other.

Syntax​

st_crosses ( geo1, geo2 )

Arguments​

  • geo1: The first GEOMETRY value.
  • geo2: The second GEOMETRY value.

Returns​

A value of type BOOLEAN, indicating whether the two input GEOMETRY values cross each other.

Whether two geometries cross depends on their topological dimensions:

  • If the geometries have different topological dimensions, they cross if their interiors intersect and part of the interior of the lower-dimensional geometry lies outside the higher-dimensional geometry.
  • If both geometries are one-dimensional (linestrings or multilinestrings), they cross if their interiors intersect only at points.
  • Otherwise, they do not cross. Two zero-dimensional geometries (points or multipoints) and two two-dimensional geometries (polygons or multipolygons) never cross.

The result does not depend on the order of the arguments.

The function returns false if any of the inputs is empty.

The function does not support geometry collections.

For more details and the formal definition, see the Crosses predicate in the DE-9IM matrix definition.

The function returns NULL if any of the inputs is NULL.

Error conditions​

Examples​

SQL
-- Returns true for two linestrings whose interiors intersect at a point.
> SELECT st_crosses(st_geomfromtext('LINESTRING(0 0,2 2,4 4)'),st_geomfromtext('LINESTRING(0 1,2 1,3 1)'));
true
-- Returns true for a linestring that passes through the interior of a polygon and leaves it.
> SELECT st_crosses(st_geomfromtext('LINESTRING(0 0,10 10)'),st_geomfromtext('POLYGON((0 0,0 5,5 5,5 0,0 0))'));
true
-- Returns false for a linestring that runs along the boundary of a polygon but never enters its interior.
> SELECT st_crosses(st_geomfromtext('LINESTRING(0 0,10 0)'),st_geomfromtext('POLYGON((0 0,0 5,5 5,5 0,0 0))'));
false
-- Returns true for a multipoint with one point in the interior of a linestring and one point outside it.
> SELECT st_crosses(st_geomfromtext('MULTIPOINT(1 0,1 1)'),st_geomfromtext('LINESTRING(0 0,1 0,3 3)'));
true