PostGISSpatial Relationships

ST_3DIntersects

What is ST_3DIntersects?

ST_3DIntersects is a PostGIS function that returns true if two geometries share any portion of space in three dimensions. Unlike its 2D counterpart ST_Intersects, it takes Z coordinates into account, so two geometries whose XY shadows overlap but sit at different elevations will not be reported as intersecting.

SQL
ST_3DIntersects(geometry geomA, geometry geomB)boolean

The function supports points, linestrings, polygons, triangles, polyhedral surfaces, and TIN geometries. It is implemented on top of SFCGAL for solid-to-solid cases and falls back to GEOS for simpler types.

When would you use ST_3DIntersects?

Use ST_3DIntersects when your data has meaningful elevation — BIM models, underground utility networks, flight paths, or building floors — and a pure 2D overlap check would produce false positives. For example, testing whether an aircraft trajectory actually crosses through a restricted airspace volume, or whether two pipes on different floors of a plant share space, requires a true 3D predicate.

SQL
1SELECT a.id, b.id
2FROM pipes a
3JOIN pipes b ON ST_3DIntersects(a.geom, b.geom)
4WHERE a.id < b.id;

FAQs

How is ST_3DIntersects different from ST_Intersects?

ST_Intersects collapses geometries to their XY footprint before testing, so a point at (0, 0, 10) "intersects" a polygon at (0, 0, 0). ST_3DIntersects requires the geometries to share an actual 3D location, so the same point and polygon would not intersect unless the polygon's elevation also passes through Z = 10.

Does ST_3DIntersects use a spatial index?

Yes, PostGIS GiST indexes store 3D bounding boxes when the geometries have Z values, so ST_3DIntersects can use them as a first-pass filter. Create a standard GiST index with CREATE INDEX ... USING GIST (geom) and the planner will pick it up.

What happens if one geometry is 2D and the other is 3D?

2D geometries are treated as having Z = 0. A 2D polygon will therefore only 3D-intersect geometries that pass through the Z = 0 plane. Mixing dimensions is usually a sign that your data model needs attention — promote 2D geometries to 3D with ST_Force3D before running 3D predicates.

Which geometry types are supported?

Points, linestrings, polygons, multi-variants of those, plus TINs and polyhedral surfaces. For true solids you need PostGIS with SFCGAL enabled, otherwise the function falls back to a 2D-aware GEOS implementation that may not return correct results for volumetric bodies.