ST_3DDWithin¶
Introduction: Return true if the 3D Euclidean distance between A and B is less than or equal to distance. Mirrors PostGIS ST_3DDWithin. Polymorphic over input type:
(Geometry, Geometry, Double)— 3D distance via JTS; coordinates without a Z dimension are treated asz = 0.(Box3D, Box3D, Double)— closed-interval 3D distance between two axis-aligned cuboids. ThrowsIllegalArgumentExceptionon inverted bounds (xmin > xmax,ymin > ymax, orzmin > zmax).
This is distinct from ST_DWithin, which always measures planar (2D) distance regardless of input dimensionality — matching the PostGIS distinction between ST_DWithin and ST_3DDWithin.
Format:
ST_3DDWithin(A: Geometry, B: Geometry, distance: Double)ST_3DDWithin(A: Box3D, B: Box3D, distance: Double)
Return type: Boolean
Since: v1.9.1
SQL Example
SELECT ST_3DDWithin(ST_PointZ(0, 0, 0), ST_PointZ(0, 0, 3), 3.0)
Output:
true
The same points are not within 2.9 units in 3D:
SELECT ST_3DDWithin(ST_PointZ(0, 0, 0), ST_PointZ(0, 0, 3), 2.9)
Output:
false
Returns NULL if any argument is NULL.
Optimization¶
ST_3DDWithin(a, b, distance) between two Box3D columns (or two geometry columns) is planned as a distance join. The planner expands each shape's XY footprint by distance for the R-tree pass — a valid superset filter, since the XY distance between two shapes is no greater than their 3D distance — and re-checks the full 3D distance per candidate pair. See Query optimization.