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.
- 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.
| Geometry b Interior |
Geometry b Boundary |
Geometry b Exterior |
|
|---|---|---|---|
| Geometry a Boundary |
* |
* |
* |
| Geometry a Interior |
T |
* |
* |
| Geometry a Exterior |
* |
* |
* |
| Geometry b Interior | Geometry b Boundary | Geometry b Exterior | |
|---|---|---|---|
| Geometry a Boundary | * | * | * |
| Geometry a Interior | * | T | * |
| Geometry a Exterior | * | * | * |
| Geometry b Interior | Geometry b Boundary | Geometry b Exterior | |
|---|---|---|---|
| Geometry a Boundary | T | * | * |
| Geometry a Interior | * | * | * |
| Geometry a Exterior | * | * | * |
| 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.
- 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.
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.
| Geometry b Interior | Geometry b Boundary | Geometry b Exterior | |
|---|---|---|---|
| Geometry a Boundary | * | * | * |
| Geometry a Interior | T | * | T |
| Geometry a Exterior | * | * | * |
| 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.
| Geometry b Interior | Geometry b Boundary | Geometry b Exterior | |
|---|---|---|---|
| Geometry a Boundary | * | * | * |
| Geometry a Interior | T | * | T |
| Geometry a Exterior | T | * | * |
| 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.

| Geometry b Interior | Geometry b Boundary | Geometry b Exterior | |
|---|---|---|---|
| Geometry a Boundary | * | * | * |
| Geometry a Interior | F | T | * |
| Geometry a Exterior | * | * | * |
| Geometry b Interior | Geometry b Boundary | Geometry b Exterior | |
|---|---|---|---|
| Geometry a Boundary | T | * | * |
| Geometry a Interior | F | * | * |
| Geometry a Exterior | * | * | * |
| Geometry b Interior | Geometry b Boundary | Geometry b Exterior | |
|---|---|---|---|
| Geometry a Boundary | * | T | * |
| Geometry a Interior | F | * | * |
| Geometry a Exterior | * | * | * |