Appearance
ST_INTERSECTION
Calculates the intersecting shapes of two GEOGRAPHY objects.
This function is symmetric, meaning:
ST_INTERSECTION(a, b)=ST_INTERSECTION(b, a)
See also:
Syntax
sql
ST_INTERSECTION(<a>, <b>)Arguments
<a>and<b>: The twoGEOGRAPHYobjects to intersect
Returns
Returns a GEOGRAPHY object representing the portion of <a> that overlaps with <b>. If <a> and <b> do not intersect, an empty GEOGRAPHY object is returned.
If <a> and <b> are of different subtypes, the following rules apply:
<a> subtype | <b> subtype | Behavior |
|---|---|---|
ST_Point | ST_Point | Returns <a> if <b> equals <a>, otherwise returns empty. |
ST_Point | ST_Linestring | Returns <a> if it lies on the line of <b>, otherwise empty. |
ST_Point | ST_Polygon | Returns <a> if it is contained within <b>, otherwise empty. If <a> touches <b>, <a> is returned. |
ST_Linestring | ST_Linestring | Returns an ST_GeometryCollection of all overlapping areas of two linestrings. Can return an ST_Point if the lines only overlap in one place, or an ST_Linestring if they overlap exactly once. |
ST_Linestring | ST_Polygon | Returns an ST_GeometryCollection containing overlapping parts of the ST_Linestring. If the polygon touches the linestring, the touching part of the linestring is returned. |
ST_Polygon | ST_Polygon | Returns a multi-shape containing the intersection, or empty if there is no overlap. As in the other cases, touching parts are considered part of the intersection. |
Example
sql
SELECT ST_AsText(ST_Intersection('POINT(0 0)'::GEOGRAPHY, 'LINESTRING(2 0,0 2)'::GEOGRAPHY));
-- GEOMETRYCOLLECTION EMPTY
SELECT ST_AsText(ST_Intersection('POINT(0 0)'::GEOGRAPHY, 'LINESTRING(0 0,0 2 )'::GEOGRAPHY));
-- POINT(0 0)