Returns a geometry object representing the set of points shared by two input geometry objects. Use ST_Intersection together with ST_Intersects to clip geometries — for example, to extract only the portion of a road network that falls within a specific region.
Syntax
geometry ST_Intersection(geometry geomA, geometry geomB)
geography ST_Intersection(geography geogA, geography geogB)
geometry ST_Intersection(geometry set gField)Parameters
| Parameter | Description |
|---|---|
geomA, geomB | The two geometry objects. |
geogA, geogB | The two geography objects. |
gField | The geometry field for the aggregate form. |
Return type
Returns geometry for geometry inputs and for the aggregate form. Returns geography for geography inputs.
| Condition | Return value |
|---|---|
| The two objects intersect | A geometry object representing the intersection |
| The two objects do not intersect | An empty geometry object |
Usage notes
ST_Intersection drops M coordinates from all input objects.
GeometryCollection objects are not supported.
For geography inputs, the function converts the objects to geometry, computes the intersection in a planar spatial reference, and then transforms the result back to geography using the World Geodetic System 1984 (WGS 84) coordinate system.
The aggregate form (ST_Intersection(geometry set gField)) applies intersection operations on all rows in a geometry column in sequence and returns the cumulative intersection.
Examples
Intersect two polygons
SELECT ST_AsText(
ST_Intersection(
'POLYGON((0 0,0 2,2 2,2 0,0 0))'::geometry,
'POLYGON((0 0,3 0,3 1,0 1,0 0))'::geometry
)
);Result:
st_astext
--------------------------------
POLYGON((0 0,0 1,2 1,2 0,0 0))
(1 row)Aggregate intersection across a table
The following example creates a table with 101 rows — one small polygon and 100 circular buffers — and then computes the intersection of all rows.
CREATE TABLE agg_result(id integer, geom geometry);
INSERT INTO agg_result VALUES(0, ST_GeomFromText('POLYGON((0 0, 0 0.5, 0.5 0.5, 0.5 0, 0 0))'));
INSERT INTO agg_result
SELECT i, ST_Buffer('POINT(0 0)', 0.8 + random()*0.1)
FROM generate_series(1, 100) AS i;
SELECT ST_AsText(ST_Intersection(geom)) FROM agg_result;Result:
st_astext
----------------------------------------
POLYGON((0 0,0 0.5,0.5 0.5,0.5 0,0 0))
(1 row)The aggregate intersection equals the small polygon because it is contained within all 100 circular buffers.
