ST_ZMax
What is ST_ZMax?
ST_ZMax is a PostGIS accessor that returns the maximum Z (elevation / altitude) coordinate of a geometry's 3D bounding box.
1ST_ZMax(geometry geom) → float
2ST_ZMax(box3d box) → floatWhen would you use ST_ZMax?
Use ST_ZMax whenever elevation matters — finding the highest point of a LiDAR swath, computing the top of a building, selecting flight-track segments above an altitude threshold, or partitioning 3D data by vertical band.
1SELECT id
2FROM buildings
3WHERE ST_ZMax(geom) > 100;FAQs
What does ST_ZMax return for a 2D geometry?
For 2D geometries the "Z" is treated as 0, so ST_ZMax returns 0. If you need to distinguish true 2D from "Z = 0" data, test ST_NDims(geom) >= 3 first.
Does ST_ZMax account for curved segments?
Z of a curve is linearly interpolated between control points, so the maximum Z is one of the control-point Zs. PostGIS's cached bounding box takes care of this automatically.
What about empty geometries?
NULL. Empty geometries have no bounding box. Filter or coalesce in reporting queries.
Can I apply ST_ZMax to a box3d directly?
Yes — ST_ZMax(box3d) returns the maximum Z of the box. This overload is useful when you already have a box3d from ST_3DExtent or Box3D without needing to re-cast to geometry.