Comparison functions for geographic features
Certain spatial functions return information about ways in which geographic features relate to one another or compare with one another. Other spatial functions return information as to whether two definitions of coordinate systems or two spatial reference systems are the same.
Functions that determine whether a geometry contains another one
The ST_Contains and ST_Within functions both take two geometries as input and determine whether the interior of one intersects the interior of the other.
In colloquial terms, ST_Contains determines whether the first geometry that is specified encloses the second geometry (whether the first contains the second). ST_Within determines whether the first geometry is completely inside the second (whether the first is within the second).
Functions that determine whether geometries intersect
The ST_Intersects, ST_Crosses, ST_Overlaps, and ST_Touches functions determine whether one geometry intersects another.
- ST_Intersects tests to determine whether the two specified geometries 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.
- ST_Crosses 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 specified as input to ST_Overlaps 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.
- ST_Touches determines whether the boundaries of two geometries intersect.
Functions that compare geometry envelopes
The ST_EnvIntersects and ST_MBRIntersects functions determine whether the smallest rectangle that encloses one geometry intersects with the smallest rectangle (an envelope) that encloses another geometry.
Multipolygons, polygons, multilinestrings, and crooked linestrings abut against the sides of their envelopes; horizontal linestrings, vertical linestrings, and points are slightly smaller than their envelopes. The ST_EnvIntersects function tests to determine whether envelopes of geometries intersect.
The smallest rectangular area into which a geometry can fit is called a minimum bounding rectangle (MBR). The envelopes surrounding multipolygons, polygons, multilinestrings, and crooked linestrings are actually MBRs. But the envelopes surrounding horizontal linestrings, vertical linestrings, and points are not MBRs, because they do not constitute a minimum area in which these latter geometries fit. These latter geometries occupy no definable space and therefore cannot have MBRs. Nevertheless, a convention has been adopted whereby they are referred to as their own MBRs. Therefore, with respect to multipolygons, polygons, multilinestrings, and crooked linestrings, ST_MBRIntersects tests the intersection of the same surrounding rectangles that ST_EnvIntersects tests. But for horizontal linestrings, vertical linestrings, and points, ST_MBRIntersects tests the intersections of these geometries themselves.
Function that determines whether geometries do not intersect
The ST_Disjoint function returns a value of 1 (one) if the intersection of the two geometries is an empty set. This function returns the exact opposite of what ST_Intersects returns.
Geometry b Interior | Geometry b Boundary | Geometry b Exterior | |
---|---|---|---|
Geometry a Boundary | F | F | * |
Geometry a Interior | F | F | * |
Geometry a Exterior | * | * | * |