Box3D
What is Box3D?
Box3D is a PostGIS function that returns the 3D bounding box of a geometry as the internal box3d type — an axis-aligned cuboid defined by minimum and maximum X, Y, and Z values.
Box3D(geometry geom) → box3dFor 2D geometries, the Z component of the returned box is zero on both sides. Casting the result to text yields BOX3D(xmin ymin zmin, xmax ymax zmax).
When would you use Box3D?
Use Box3D whenever elevation matters — BIM models, LiDAR tiles, underground utility networks, airspace analysis — and you want a compact descriptor of the geometry's 3D extent. Box3D is the natural input to functions such as ST_3DMakeBox and is the type you receive back from the ST_3DExtent aggregate.
1SELECT id, Box3D(geom) AS bbox
2FROM buildings
3WHERE Z_max > 30;FAQs
What's the difference between Box3D and Box2D?
Box2D ignores Z entirely and returns a 2D box2d. Box3D returns a box3d that also tracks minimum and maximum Z. If your geometries are 2D, Box3D still returns a valid result with zmin = zmax = 0.
Does Box3D handle M values?
No, Box3D tracks only X, Y, and Z — M (measure) coordinates are ignored. If you need both Z and M extents you must extract them separately with ST_ZMin, ST_ZMax, and aggregate ST_MMin/ST_MMax on the coordinate arrays.
How does Box3D behave for empty geometries?
Empty geometries return NULL from Box3D. Always guard against empties with NOT ST_IsEmpty(geom) in aggregation queries.
Is Box3D the same as the `box3d` aggregate?
Box3D (this function) returns the bbox of a single geometry. ST_3DExtent is the aggregate form that unions the box3d across a set of geometries and is what you typically use in GROUP BY queries to compute a layer's overall 3D extent.