Functions that check intersections between geometries

The EnvelopesIntersect, ST_Intersects, ST_Crosses, ST_Overlaps, and ST_Touches functions all determine whether one geometry intersects another.

These functions differ mainly as to the scope of intersection that they test for.

The EnvelopesIntersect function determines if the minimum bounding rectangles of two geometries intersect.

The ST_Intersects function tests to determine whether the two geometries given to it meet one of four conditions: that the geometries' interiors intersect, that their boundaries intersect, that the boundary of the first geometry intersects with the interior of the second, or that the interior of the first geometry intersects with the boundary of the second.

The ST_Crosses function is used to analyze the intersection of geometries of different dimensions, with one exception: it can also analyze the intersection of linestrings. In all cases, the place of intersection is itself considered a geometry; and ST_Crosses requires that this geometry be of a lesser dimension than the greater of the intersecting geometries (or, if both are linestrings, that the place of intersection be of a lesser dimension than a linestring). For example, the dimensions of a linestring and polygon are 1 and 2, respectively. If two such geometries intersect, and if the place of intersection is linear (the linestring's path along the polygon), then that place can itself be considered a linestring. And because a linestring's dimension (1) is lesser than a polygon's (2), ST_Crosses, after analyzing the intersection, would return a value of 1.

The geometries given to the ST_Overlaps function as input must be of the same dimension. ST_Overlaps requires that these geometries overlap part-way, forming a new geometry (the region of overlap) that is the same dimension as they are.

The ST_Touches function determines whether the boundaries of two geometries intersect.

EnvelopesIntersect

Use the EnvelopesIntersect spatial function to determine if the minimum bounding rectangles of two geometries intersect.

The EnvelopesIntersect function accepts two types of input parameters:
  • Two geometries

    EnvelopesIntersect returns 1 if the envelope of the first geometry intersects the envelope of the second geometry. Otherwise, 0 (zero) is returned.

  • A geometry, four type DOUBLE coordinate values that define the lower-left and upper-right corners of a rectangular window, and the spatial reference system identifier.

    EnvelopesIntersect returns 1 if the envelope of the first geometry intersects with the envelope defined by the four type DOUBLE values. Otherwise, 0 (zero) is returned.

If one of the input geometries is empty or null, null is returned.

ST_Intersects

Use ST_Intersects to determine whether two geometries intersect.

ST_Intersects returns a value of 1 (one) if the intersection does not result in an empty set.

The ST_Intersects function returns 1 (one) if the conditions of any of the following pattern matrices returns TRUE.
Table 1. Matrix for ST_Intersects (1). The ST_Intersects function returns 1 (one) if the interiors of both geometries intersect.
 

Geometry b Interior

Geometry b Boundary

Geometry b Exterior

Geometry a Boundary

*

*

*

Geometry a Interior

T

*

*

Geometry a Exterior

*

*

*

Table 2. Matrix for ST_Intersects (2). The ST_Intersects function returns 1 (one) if the boundary of the first geometry intersects the boundary of the second geometry.
  Geometry b Interior Geometry b Boundary Geometry b Exterior
Geometry a Boundary * * *
Geometry a Interior * T *
Geometry a Exterior * * *
Table 3. Matrix for ST_Intersects (3). The ST_Intersects function returns 1 (one) if the boundary of the first geometry intersects the interior of the second.
  Geometry b Interior Geometry b Boundary Geometry b Exterior
Geometry a Boundary T * *
Geometry a Interior * * *
Geometry a Exterior * * *
Table 4. Matrix for ST_Intersects (4). The ST_Intersects function returns 1 (one) if the boundaries of either geometry intersect.
  Geometry b Interior Geometry b Boundary Geometry b Exterior
Geometry a Boundary * T *
Geometry a Interior * * *
Geometry a Exterior * * *

ST_Crosses

Use ST_Crosses to determine whether one geometry crosses another.

ST_Crosses takes two geometries and returns a value of 1 (one) if:
  • The intersection results in a geometry whose dimension is less than the maximum dimension of the source geometries.
  • The intersection set is interior to both source geometries.
ST_Crosses returns a null if the first geometry is a polygon or multipolygon or if the second geometry is a point or multipoint. For all other combinations, ST_Crosses returns either a value of 1 (indicating that the two geometries cross) or a value of 0 (indicating that they do not cross).

The following figure illustrates multipoints crossing linestring, linestring crossing linestring, multiple points crossing a polygon, and linestring crossing a polygon. In three of the four cases, geometry b crosses geometry a. In the fourth case geometry a is a multipoint which does not cross the line, but does touch the area inside the geometry b polygon.

The dark geometries represent geometry a; the gray geometries represent geometry b.
Figure 1. ST_Crosses
Begin figure description. Illustrating the intersection of geometries. End figure description.
The pattern matrix in the following table applies if the first geometry is a point or multipoint, or if the first geometry is a linestring or multilinestring, and the second geometry is a polygon. The matrix states that the interiors must intersect and that the interior of the primary (geometry a) must intersect the exterior of the secondary (geometry b).
Table 5. Matrix for ST_Crosses (1)
  Geometry b Interior Geometry b Boundary Geometry b Exterior
Geometry a Boundary * * *
Geometry a Interior T * T
Geometry a Exterior * * *
The pattern matrix in the following table applies if the first and second geometries are both linestrings or multilinestrings. The 0 indicates that the intersection of the interiors must be a point (dimension 0). If the dimension of this intersection is 1 (intersect at a linestring), the ST_Crosses function returns a value of 0 (indicating that the geometries do not cross); however, the ST_Overlaps function returns a value of 1 (indicating that the geometries overlap).
Table 6. Matrix for ST_Crosses (2)
  Geometry b Interior Geometry b Boundary Geometry b Exterior
Geometry a Boundary * * *
Geometry a Interior 0 * *
Geometry a Exterior * * *

ST_Overlaps

Use ST_Overlaps to determine whether two geometries of the same dimension overlap.

ST_Overlaps compares two geometries of the same dimension. It returns a value of 1 (one) if their intersection set results in a geometry that is different from both, but that has the same dimension.

The dark geometries represent geometry a; the gray geometries represent geometry b. In all cases, both geometries have the same dimension, and one overlaps the other partway. The area of overlap is a new geometry; it has the same dimension as geometries a and b.

The following figure illustrates overlaps in geometries. The three examples show overlaps with points, linestrings, and polygons. With points the actual points overlap. With linestrings, a portion of the line overlaps. With polygons a portion of the area overlaps.
Figure 2. ST_Overlaps
Begin figure description. This figure shows overlapping geometries that create a new geometry. End figure description.
The pattern matrix in Table 7 applies if the first and second geometries are both either points, multipoints, polygons, or multipolygons. ST_Overlaps returns a value of 1 if the interior of each geometry intersects the other geometry's interior and exterior.
Table 7. Matrix for ST_Overlaps (1)
  Geometry b Interior Geometry b Boundary Geometry b Exterior
Geometry a Boundary * * *
Geometry a Interior T * T
Geometry a Exterior T * *
The pattern matrix in Table 8 applies if the first and second geometries are both linestrings or multilinestrings. In this case, the intersection of the geometries must result in a geometry that has a dimension of 1 (another linestring). If the dimension of the intersection of the interiors is 0, ST_Overlaps returns a value of 0 (indicating that the geometries do not overlap); however the ST_Crosses function would return a value of 1 (indicating that the geometries cross).
Table 8. Matrix for ST_Overlaps (2)
  Geometry b Interior Geometry b Boundary Geometry b Exterior
Geometry a Boundary * * *
Geometry a Interior 1 * T
Geometry a Exterior T * *

ST_Touches

Use ST_Touches to determine whether the boundaries of two geometries intersect.

ST_Touches returns a value of 1 (one) if all the points common to both geometries can be found only on the boundaries. The interiors of the geometries must not intersect one another. At least one geometry must be a linestring, polygon, multilinestring, or multipolygon.

The dark geometries represent geometry a; the gray geometries represent geometry b. In all cases, the boundary of geometry b intersects geometry a. The interior of geometry b remains separate from geometry a.

The following figure shows examples of touching with types of geometries, such as point and linestring, linestring and linestring, point and polygon, multipoint and polygon, and linestring and polygon.
Figure 3. ST_Touches
Begin figure description. Examples of types of geometries touching. End figure description.
The pattern matrices show that the ST_Touches function returns 1 (one) when the interiors of the geometry do not intersect, and the boundary of either geometry intersects the other's interior or its boundary.
Table 9. Matrix for ST_Touches (1)
  Geometry b Interior Geometry b Boundary Geometry b Exterior
Geometry a Boundary * * *
Geometry a Interior F T *
Geometry a Exterior * * *
Table 10. Matrix for ST_Touches (2)
  Geometry b Interior Geometry b Boundary Geometry b Exterior
Geometry a Boundary T * *
Geometry a Interior F * *
Geometry a Exterior * * *
Table 11. Matrix for ST_Touches (3)
  Geometry b Interior Geometry b Boundary Geometry b Exterior
Geometry a Boundary * T *
Geometry a Interior F * *
Geometry a Exterior * * *