The ST_Intersection() function
The ST_Intersection() function takes two ST_Geometry objects and returns the intersection set as an ST_Geometry object. If the two objects do not intersect, the return value is an empty geometry.
Syntax
ST_Intersection(g1 ST_Geometry, g2 ST_Geometry)
Usage
If an ST_LineString intersects an ST_Polygon, the ST_Intersection() function returns the portion of the ST_LineString common to the interior and boundary of the ST_Polygon as an ST_MultiLineString. The ST_MultiLineString contains more than one ST_LineString if the source ST_LineString intersects the ST_Polygon with two or more discontinuous segments.
Return type
ST_Geometry
Example
The fire marshal must obtain the areas of the hospitals, schools, and nursing homes that are intersected by the radius of a possible hazardous waste contamination.
CREATE TABLE sensitive_areas (id integer,
name varchar(128),
size float,
type varchar(10),
zone ST_Polygon);
CREATE TABLE hazardous_sites (site_id integer,
name varchar(40),
location ST_Point);
SELECT hs.site_id, SUM(ST_Area(ST_Intersection(sa.zone,
ST_Buffer(hs.location,(5 * 5280)))::ST_MultiPolygon))
FROM sensitive_areas sa, hazardous_sites hs
GROUP BY hs.site_id;
site_id (sum)
102 87000000.00000
59 77158581.63280