The ST_Crosses() function

The ST_Crosses() function returns t (TRUE) if the intersection of two geometry objects results in an ST_Geometry object whose dimension is one less than the maximum dimension of the source objects.

Syntax

ST_Crosses(g1 ST_Geometry, g2 ST_Geometry)

Usage

The intersection object must contain points that are interior to both source geometries and it must not be equal to either of the source objects. Otherwise, it returns f (FALSE).

Figure 1: Crossing geometries

This graphic shows various geometric objects that cross each other.

The results of the spatial relationship of the ST_Crosses() function can be understood or verified by comparing the results with a pattern matrix that represents the acceptable values for the DE-9IM. The ST_Crosses() function returns TRUE if the intersection object contains points that are interior to both source geometries, but is not equal to either of the source objects.

This ST_Crosses() function pattern matrix applies to ST_MultiPoint and ST_LineString; ST_MultiPoint and ST_MultiLineString; ST_MultiPoint and ST_Polygon; ST_MultiPoint and ST_MultiPolygon; ST_LineString and ST_Polygon; and ST_LineString and ST_MultiPolygon. The matrix states that the interiors must intersect and at least the interior of the primary (geometry a) must intersect the exterior of the secondary (geometry b).
Table 1. Pattern matrix for the ST_Crosses() function

The table is a matrix. The top row and first column identify the geometry.

Interior (b) Boundary (b) Exterior (b)
Interior (a) T * T
Boundary (a) * * *
Exterior (a) * * *
This ST_Crosses() function matrix applies to ST_LineString and ST_LineString; ST_LineString and ST_MultiLineString; and ST_MultiLineString and ST_MultiLineString. The matrix states that the dimension of the intersection of the interiors must be 0 (intersect at a point). If the dimension of this intersection was 1 (intersect at a linestring), the ST_Crosses() function would return FALSE but the ST_Overlaps() function would return TRUE.
Interior (b) Boundary (b) Exterior (b)
Interior (a) 0 * *
Boundary (a) * * *
Exterior (a) * * *

Return type

BOOLEAN

Example

The county government is considering a new regulation that states all hazardous waste storage facilities must not be within 5 miles of any waterway. The county GIS manager has an accurate representation of rivers and streams, which are stored as multilinestrings in the waterways table. However, the GIS manager has only a single point location for each of the hazardous waste storage facilities:
CREATE TABLE waterways (id     integer,
                        name   varchar(128),
                        water  ST_MultiLineString);

CREATE TABLE hazardous_sites (site_id   integer,
                              name      varchar(40),
                              location  ST_Point);
The GIS manager needs to alert the county supervisor to any existing facilities that would violate the proposed regulation. To determine whether such notification is necessary, the GIS manager must buffer the hazardous_sites locations to see whether any rivers or streams cross the buffer polygons. The ST_Crosses() function compares the buffered hazardous_sites with waterways, returning only those records where the waterway crosses over the county's proposed regulated radius:
SELECT ww.name waterway, hs.name hazardous_site
   FROM waterways ww, hazardous_sites hs
   WHERE ST_Crosses(ST_Buffer(hs.location,(5 * 5280)),ww.water);


waterway        Fedders creek
hazardous_site  Landmark Industrial
The following figure shows that the 5-mile buffered radius of the hazardous waste sites crosses the stream network that runs through the county's administrative district. Because the stream network is defined as an ST_MultiLineString, all linestring segments that are part of the segments that cross the radius are included in the result set.
Figure 2: Hazardous waste sites and the stream network.

A hazardous waste site buffer crosses a stream network.