ST_XMax

更新时间:
复制 MD 格式

Returns the X maximum of a 2D or 3D bounding box or a geometry.

Syntax

float ST_XMax(box3d aGeomorBox2DorBox3D);

Parameters

ParameterDescription
aGeomorBox2DorBox3DThe Box2D object, Box3D object, or geometry object to query.

Description

ST_XMax returns the maximum x coordinate on the bounding box of the input object.

Although the parameter type is defined as box3d, ST_XMax also accepts Box2D and geometry values through auto-casting. Auto-casting does not apply to string representations of Box2D or geometry objects — passing a string directly causes a parse error.
  • This function supports 3D objects and preserves z coordinates.

  • This function supports circular strings and curves.

Examples

Box3D object

SELECT ST_XMax('BOX3D(1 2 3, 4 5 6)');
 st_xmax
---------
       4
(1 row)

Geometry object (using explicit cast)

SELECT ST_XMax(ST_GeomFromText('LINESTRING(1 3 4, 5 6 7)'));
 st_xmax
---------
       5
(1 row)

Box2D object (using explicit cast)

SELECT ST_XMax(CAST('BOX(-3 2, 3 4)' AS box2d));
 st_xmax
---------
       3
(1 row)

Passing a geometry string directly — this does not work

-- Passing a raw string without an explicit cast fails because ST_XMax
-- attempts to auto-cast it to box3d, not geometry.
SELECT ST_XMax('LINESTRING(1 3, 5 6)');
-- ERROR:  BOX3D parser - doesn't start with BOX3D(

Cast the string to the correct type before passing it to ST_XMax:

SELECT ST_XMax('LINESTRING(0 1,2 3)'::geometry);
 st_xmax
---------
       2
(1 row)

See also

  • [ST_XMin](): Returns the minimum x coordinate on the bounding box.

  • [ST_YMax](): Returns the maximum y coordinate on the bounding box.

  • [ST_YMin](): Returns the minimum y coordinate on the bounding box.

  • [ST_ZMax](): Returns the maximum z coordinate on the bounding box.

  • [ST_ZMin](): Returns the minimum z coordinate on the bounding box.