ST_ZMin
What is ST_ZMin?
ST_ZMin is a PostGIS accessor that returns the minimum Z (elevation) coordinate of a geometry's 3D bounding box.
1ST_ZMin(geometry geom) → float
2ST_ZMin(box3d box) → floatWhen would you use ST_ZMin?
Use ST_ZMin whenever you need the lowest elevation of a geometry — finding the base of a building, the deepest point of a pipeline, the ground-level of a LiDAR tile, or filtering out geometries below sea level.
1SELECT id
2FROM pipelines
3WHERE ST_ZMin(geom) < -10;FAQs
What does ST_ZMin return for 2D geometries?
It returns 0, because 2D geometries implicitly have Z = 0. To detect true 2D data, test ST_NDims(geom) >= 3 before relying on Z.
Is ST_ZMin cached?
Yes — PostGIS caches the bounding box for 3D geometries alongside the usual 2D bbox. ST_ZMin is O(1) regardless of the number of vertices.
What about empty geometries?
NULL. Filter empties or use COALESCE to protect aggregates and reports.
Does ST_ZMin work on box3d?
Yes — there is an overload that takes a box3d directly. This is convenient when reducing a box3d produced by ST_3DExtent or similar aggregates into its numeric components.