ST_BoundingDiagonal

更新时间:
复制 MD 格式

Returns a LineString that represents the diagonal of the bounding box of a geometry object.

Syntax

geometry ST_BoundingDiagonal(geometry geom, boolean fits);

Parameters

ParameterDescription
geomThe geometry object.
fitsSpecifies whether the tightest possible bounding box is required. Default: false. When false, the function may use a slightly larger bounding box, which is faster to compute for geometries with many vertices. In either case, the returned bounding box always covers the input geometry.

Description

  • If geom is empty, the returned LineString is also empty.

  • If geom is not empty, the function returns a two-point LineString. The start point holds the minimum value of each dimension; the end point holds the maximum value of each dimension.

  • The returned LineString retains the spatial reference identifier (SRID) and dimensions of geom.

  • This function supports 3D geometries and preserves Z coordinates.

  • This function supports M coordinates.

Examples

The following examples show how to use ST_BoundingDiagonal to retrieve the extent of a geometry.

Get the diagonal of a line's bounding box

SELECT ST_AsText(ST_BoundingDiagonal('LINESTRING(2 2,0 0)'::geometry));

Output:

      st_astext
---------------------
 LINESTRING(0 0,2 2)
(1 row)

See also

  • ST_Envelope — returns the bounding box as a polygon instead of a diagonal line

  • ST_StartPoint — retrieves the minimum-value corner of the diagonal

  • ST_EndPoint — retrieves the maximum-value corner of the diagonal

  • ST_X, ST_Y, ST_Z, ST_M — extract individual coordinate values from the result