ST_3DMakeBox
What is ST_3DMakeBox?
ST_3DMakeBox is a PostGIS constructor that builds a box3d value from two 3D corner points — the lower-left-bottom and upper-right-top of the bounding cuboid.
ST_3DMakeBox(geometry point3DLowLeftBottom, geometry point3DUpRightTop) → box3dWhen would you use ST_3DMakeBox?
Use ST_3DMakeBox whenever you need to construct a 3D bounding box from two points — for example, framing a LiDAR tile, defining a search volume for underground utilities, or initialising a 3D viewer. The resulting box3d is also the right input type for the &&& 3D bounding-box operator.
1SELECT id
2FROM building_parts
3WHERE geom &&& ST_3DMakeBox(
4 ST_MakePoint(-9.20, 38.70, 0),
5 ST_MakePoint(-9.10, 38.75, 100)
6);FAQs
Do the input points have to be 3D?
Yes. Both arguments must be 3D points (XYZ). For 2D points, the Z is implicitly 0, but you should convert with ST_Force3D to avoid ambiguity.
How does ST_3DMakeBox differ from ST_MakeBox2D?
ST_MakeBox2D returns a 2D box2d and ignores Z. ST_3DMakeBox returns a box3d that tracks Z min/max. Choose based on whether your index and queries are 2D (&&) or 3D (&&&).
What SRID does box3d carry?
Like box2d, the box3d type is SRID-less. Any SRID reasoning must happen at the query level. To obtain a fully-fledged SRIDed geometry cuboid, construct it from the box corners and set the SRID explicitly.
How do I use the result with a spatial index?
Use the 3D bounding-box operator &&& between a geometry column and the box3d: geom &&& ST_3DMakeBox(p1, p2). PostGIS GiST indexes on geometries with Z support this operator natively.