ST_3DDFullyWithin
What is ST_3DDFullyWithin?
ST_3DDFullyWithin returns true if every point of geometry g1 is within a given 3D Euclidean distance of geometry g2, and vice versa — equivalently, the 3D maximum distance between the two geometries is less than or equal to the threshold. It is the 3D counterpart of ST_DFullyWithin.
ST_3DDFullyWithin(geometry g1, geometry g2, float distance) → booleanDistance is in the CRS units of the inputs — typically metres for projected 3D data. There is no geography overload.
When would you use ST_3DDFullyWithin?
Use ST_3DDFullyWithin to verify that two 3D features are entirely within a distance tolerance in three-dimensional space: confirming a cable run never leaves a clearance envelope, validating that a component fits inside a manufacturing tolerance box, or auditing that a trajectory stays inside a safety corridor in all three axes. It is stricter than ST_3DDWithin, which only requires the geometries to touch within the threshold.
1SELECT id
2FROM cable_runs
3WHERE ST_3DDFullyWithin(geom, reference_envelope, 0.25);FAQs
How does it differ from ST_3DDWithin?
ST_3DDWithin tests the minimum 3D distance between the two geometries; ST_3DDFullyWithin tests the maximum 3D distance. The latter is much stricter — it requires every part of each geometry to be close to the other.
Which index should I use?
An N-dimensional GiST index: CREATE INDEX ON tbl USING GIST (geom gist_geometry_ops_nd). This lets the planner prune candidates based on 3D bounding boxes.
What units does the distance use?
The CRS units of the inputs. There is no geography overload; for lat/lon data, reproject to a projected CRS in metres.
What happens with 2D input?
Missing Z values are treated as 0, which makes the 3D test collapse onto 2D. Ensure both inputs are truly 3D for meaningful results.