Skip to content

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 two GEOGRAPHY objects 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> subtypeBehavior
ST_PointST_PointReturns <a> if <b> equals <a>, otherwise returns empty.
ST_PointST_LinestringReturns <a> if it lies on the line of <b>, otherwise empty.
ST_PointST_PolygonReturns <a> if it is contained within <b>, otherwise empty. If <a> touches <b>, <a> is returned.
ST_LinestringST_LinestringReturns 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_LinestringST_PolygonReturns 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_PolygonST_PolygonReturns 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)