ST_Envelope

更新时间:
复制 MD 格式

Returns the minimum bounding box of a geometry object as a polygon.

Syntax

geometry ST_Envelope(geometry g1);

Parameters

ParameterDescription
g1The geometry object.

Usage notes

  • Bounding box coordinates are returned as FLOAT8 values.

  • The bounding box is represented as a polygon defined by five corner points in this order: (MINX,MINY), (MINX,MAXY), (MAXX,MAXY), (MAXX,MINY), (MINX,MINY).

  • For degenerate inputs such as a vertical line or a point, the function returns a geometry of lower dimension than a polygon — either a LineString or a point.

Examples

Standard case: A diagonal line segment returns a rectangular bounding box.

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

Output:

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

Degenerate case: A vertical line segment has no width, so the bounding box degenerates to a LineString.

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

Output:

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