Returns a LineString that represents the diagonal of the bounding box of a geometry object.
Syntax
geometry ST_BoundingDiagonal(geometry geom, boolean fits);Parameters
| Parameter | Description |
|---|---|
geom | The geometry object. |
fits | Specifies 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
geomis empty, the returnedLineStringis also empty.If
geomis not empty, the function returns a two-pointLineString. The start point holds the minimum value of each dimension; the end point holds the maximum value of each dimension.The returned
LineStringretains the spatial reference identifier (SRID) and dimensions ofgeom.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 lineST_StartPoint— retrieves the minimum-value corner of the diagonalST_EndPoint— retrieves the maximum-value corner of the diagonalST_X,ST_Y,ST_Z,ST_M— extract individual coordinate values from the result