Fork me on GitHub

ST_Intersection

Signatures

GEOMETRY ST_Intersection(GEOMETRY geomA, GEOMETRY geomB)

Description

Computes the intersection between geomA and geomB.

geomA and geomB can be POINTs, LINESTRINGs, POLYGONs or GEOMETRYCOLLECTIONs

Implements the OpenGIS Simple Features Implementation Specification for SQL version 1.2.1.

Examples

geomA POLYGON geomB POLYGON
POLYGON((1 1, 7 1, 7 6, 1 6, 1 1)) POLYGON((3 2, 8 2, 8 8, 3 8, 3 2))
SELECT ST_Intersection(geomA, geomB) FROM input_table;
-- Answer:    POLYGON((3 6, 7 6, 7 2, 3 2, 3 6))

geomA POLYGON geomB POLYGON
POLYGON((1 1, 4 1, 4 6, 1 6, 1 1)) POLYGON((4 2, 8 2, 8 8, 4 8, 4 2))
SELECT ST_Intersection(geomA, geomB) FROM input_table;
-- Answer:    LINESTRING(4 2, 4 6)

geomA POLYGON geomB POLYGON
POLYGON((1 1, 4 1, 4 6, 1 6, 1 1)) POLYGON((4 6, 8 6, 8 8, 4 8, 4 6))
SELECT ST_Intersection(geomA, geomB) FROM input_table;
-- Answer:    POINT(4 6)

geomA POLYGON geomB LINESTRING
POLYGON((1 1, 7 1, 7 6, 1 6, 1 1)) LINESTRING(2 8, 8 2)
SELECT ST_Intersection(geomA, geomB) FROM input_table;
-- Answer:    LINESTRING(4 6, 7 3)

geomA LINESTRING geomB LINESTRING
LINESTRING(2 2, 6 6) LINESTRING(2 8, 8 2)
SELECT ST_Intersection(geomA, geomB) FROM input_table;
-- Answer:    POINT(5 5)

geomA POLYGON geomB POINT
POLYGON((1 1, 7 1, 7 6, 1 6, 1 1)) POINT(3 5)
SELECT ST_Intersection(geomA, geomB) FROM input_table;
-- Answer:    POINT(3 5)

See also