ST_Envelope

更新时间:
复制 MD 格式

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

Syntax

geometry ST_Envelope(geometry g1);

Parameters

ParameterDescription
g1The input geometry.

Usage notes

  • Bounding box coordinates use the FLOAT8 data type.

  • The bounding box is returned as a polygon defined by five corner points in this order: bottom-left (MINX,MINY), top-left (MINX,MAXY), top-right (MAXX,MAXY), bottom-right (MAXX,MINY), bottom-left (MINX,MINY).

  • For degenerate inputs — a point or a vertical line — the function returns a lower-dimensional geometry (a point or a LineString) instead of a polygon.

Examples

Standard case

A diagonal line produces a polygon bounding box:

SELECT ST_AsText(ST_Envelope('LINESTRING(0 0,2 2)'::geometry));
           st_astext
--------------------------------
 POLYGON((0 0,0 2,2 2,2 0,0 0))
(1 row)

Degenerate case: vertical line

A vertical line collapses to zero width, so the function returns a LineString:

SELECT ST_AsText(ST_Envelope('LINESTRING(0 0,0 2)'::geometry));
      st_astext
---------------------
 LINESTRING(0 0,0 2)
(1 row)