Skip to main content
Returns 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 as z = 0.
  • (Box3D, Box3D, Double) — closed-interval 3D distance between two axis-aligned cuboids. Throws IllegalArgumentException on inverted bounds (xmin > xmax, ymin > ymax, or zmin > 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. ST_3DDWithin returning true: the 3D gap is within the distance ST_3DDWithin returning false: the 3D gap exceeds the distance Returns NULL if any argument is NULL.

Signatures

ST_3DDWithin(A: Geometry, B: Geometry, distance: Double)
ST_3DDWithin(A: Box3D, B: Box3D, distance: Double)

Parameters

A
Geometry | Box3D
required
The first geometry or 3D bounding box.
B
Geometry | Box3D
required
The second geometry or 3D bounding box.
distance
Double
required
The maximum 3D distance between A and B.

Return type

true if the 3D distance between A and B is within distance.

Example

SELECT ST_3DDWithin(ST_PointZ(0, 0, 0), ST_PointZ(0, 0, 3), 3.0)
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)
false

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.