ST_ZMin

更新时间:
复制 MD 格式

Returns the minimum z coordinate of the bounding box of a Box2D, Box3D, or geometry object.

Syntax

float ST_ZMin(box3d aGeomorBox2DorBox3D);

Parameters

ParameterDescription
aGeomorBox2DorBox3DThe Box2D, Box3D, or geometry object.

Usage notes

Although the parameter type is defined as box3d, ST_ZMin also accepts Box2D and geometry values through auto-casting. However, passing a Box2D or geometry value as a string literal bypasses auto-casting and causes an error. Use ST_GeomFromEWKT or a cast expression (::geometry) to convert string input explicitly.

Additional behavior:

  • Preserves z coordinates — does not drop the z dimension from 3D objects.

  • Supports circular strings and curves.

Examples

Get the minimum z coordinate of a LineString

SELECT ST_ZMin('LINESTRING(0 1 2,3 4 5)'::geometry);
 st_zmin
---------
       2
(1 row)

Get the minimum z coordinate of a Box3D

SELECT ST_ZMin('BOX3D(1 2 3, 4 5 6)');
 st_zmin
---------
       3
(1 row)

Use ST_GeomFromEWKT to pass a geometry string

SELECT ST_ZMin(ST_GeomFromEWKT('LINESTRING(1 3 4, 5 6 7)'));
 st_zmin
---------
       4
(1 row)

Passing a geometry string directly causes an error

-- This fails because the string does not auto-cast to box3d
SELECT ST_ZMin('LINESTRING(1 3 4, 5 6 7)');
-- ERROR: BOX3D parser - doesn't start with BOX3D(

What's next

  • ST_ZMax: Returns the maximum z coordinate of the bounding box.

  • ST_XMin: Returns the minimum x coordinate of the bounding box.

  • ST_YMin: Returns the minimum y coordinate of the bounding box.