ST_Intersection
What is ST_Intersection?
ST_Intersection returns the geometry shared by two inputs — their set-theoretic intersection. If the inputs do not share any space, it returns an empty geometry. The output type depends on the inputs: polygon ∩ polygon can yield a polygon, line, or point collection depending on how they overlap.
1ST_Intersection(geometry g1, geometry g2) → geometry
2ST_Intersection(geometry g1, geometry g2, float gridSize) → geometry
3ST_Intersection(geography g1, geography g2) → geographyThe optional gridSize (PostGIS 3.1+) snaps inputs to a fixed precision grid for robustness. The geography overload is limited to POINT and LINESTRING; for polygon-on-polygon intersections on lat/lon data, reproject to a projected CRS or cast back and forth.
When would you use ST_Intersection?
Use ST_Intersection for area-of-overlap calculations and overlay analysis: computing the portion of a zoning polygon that falls inside a flood zone, the street segments passing through a construction area, or the coordinates where two flight corridors cross. Combined with ST_Area, it underpins area-weighted statistical overlays ("how much population in each census tract falls within the hazard zone").
1-- Area of each parcel that falls inside the flood hazard zone
2SELECT p.id,
3 ST_Area(ST_Intersection(p.geom, f.geom)::geography) AS flooded_m2
4FROM parcels p
5JOIN flood_zones f ON ST_Intersects(p.geom, f.geom);FAQs
Is ST_Intersection fast?
It is an expensive operation, roughly proportional to the combined vertex count of the inputs. Always pre-filter with ST_Intersects (which uses a GiST index) so you only call ST_Intersection on pairs that actually overlap.
What does it return for non-overlapping inputs?
An empty geometry — usually GEOMETRYCOLLECTION EMPTY or an empty type matching the expected result. Filter with NOT ST_IsEmpty(...) if you only want non-empty results.
What if the result is a mix of dimensions?
The output can be a GEOMETRYCOLLECTION mixing polygons, lines, and points. If you only want one dimension, follow with ST_CollectionExtract(result, 3) for polygons, 2 for lines, or 1 for points.
What does the gridSize parameter do?
It snaps inputs to a precision grid before overlay, improving robustness when vertices are nearly coincident. A typical value for metre-based data is 0.001. The parameter was added in PostGIS 3.1.