ST_Z
What is ST_Z?
ST_Z is a PostGIS function that returns the Z (elevation) coordinate of a POINT geometry. Returns NULL if the point has no Z dimension.
ST_Z(geometry point) → double precisionInput must be a POINT; non-point input returns NULL.
When would you use ST_Z?
Use ST_Z in 3D workflows — reading elevations from sampled points, computing vertical statistics, or branching logic based on altitude:
1SELECT id,
2 ST_Z(geom) AS elevation_m
3FROM dem_samples
4WHERE ST_Z(geom) > 1000;Combine with ST_X/ST_Y for full coordinate export, or with ST_DumpPoints to extract elevations for every vertex of a 3D line.
FAQs
What if the point is 2D?
ST_Z returns NULL. Check with ST_NDims or ST_Zmflag beforehand if you need a typed fallback.
What units does Z use?
Whatever the data producer stored. PostGIS does not enforce or interpret Z units — typically metres above a reference surface, but always confirm per column.
Do spatial predicates respect Z?
No — standard 2D predicates ignore Z. Use ST_3DIntersects, ST_3DDistance, ST_3DDWithin for Z-aware tests.
How do I extract Z for every vertex of a line?
SELECT ST_Z((ST_DumpPoints(line)).geom) FROM t; — dump vertices first, then call ST_Z per row.