Returns a Geometry object that represents the intersection of the input Geometry objects.
Syntax
geometry ST_Intersection(geometry geomA , geometry geomB);
geography ST_Intersection(geography geogA , geography geogB);
geometry ST_Intersection(geometry set gField);Parameters
Parameter name | Description |
geomA/geomB | The two target Geometry objects. |
geogA/geogB | The two target Geography objects. |
gField | The Geometry field. |
Description
If the two input objects do not intersect, the function returns a null object.
For Geography objects, this function wraps the Geometry function. It first transforms the Geography objects into Geometry objects, finds their intersection in a planar reference system, and then transforms the result back into a Geography object that uses the WGS84 coordinate system.
This function does not support GeometryCollection objects as input parameters.
This function discards the M coordinate values of the objects.
The aggregate function sequentially intersects all Geometry objects and returns the resulting intersection.
Examples
Default call:
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)); st_astext -------------------------------- POLYGON((0 1,2 1,2 0,0 0,0 1)) (1 row)Aggregate clipping
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; st_astext ---------------------------------------- POLYGON((0 0,0 0.5,0.5 0.5,0.5 0,0 0)) (1 row)