The ST_Envelope() function

The ST_Envelope() function returns the bounding box of a geometry object.

This is usually a rectangle, but the envelope of a point is the point itself, and the envelope of a horizontal or vertical linestring is a linestring represented by the endpoints of the source geometry.

Syntax

ST_Envelope(g1 ST_Geometry)

Return type

ST_Geometry

Example

The geotype column of the envelope_test table stores the name of the geometry subclass stored in the g1 ST_Geometry column:
CREATE TABLE envelope_test (geotype varchar(20),
                            g1      ST_Geometry);
The following INSERT statements insert each geometry subclass into the envelope_test table:
INSERT INTO envelope_test VALUES( 
   'Point', 
   ST_PointFromText('point (10.02 20.01)',1000)
);

INSERT INTO envelope_test VALUES( 
   'Linestring', 
   ST_LineFromText('linestring (10.01 20.01, 10.01 30.01, 10.01 40.01)', 1000) 
);

INSERT INTO envelope_test VALUES( 
   'Linestring', 
   ST_LineFromText('linestring (10.02 20.01,10.32 23.98,11.92 25.64)', 1000) 
);

INSERT INTO envelope_test VALUES( 
   'Polygon', 
   ST_PolyFromText('polygon ((10.02 20.01,11.92 35.64,25.02
34.15,19.15 33.94, 10.02 20.01))',1000) 
);

INSERT INTO envelope_test VALUES( 
   'Multipoint', 
   ST_MPointFromText('multipoint (10.02 20.01,10.32 23.98,11.92 25.64)', 1000) 
);

INSERT INTO envelope_test VALUES( 
   'Multilinestring', 
   ST_MLineFromText('multilinestring ((10.01 20.01,20.01
20.01,30.01 20.01), (30.01 20.01,40.01 20.01,50.01 20.01))',1000) 
);

INSERT INTO envelope_test VALUES( 
   'Multilinestring', 
   ST_MLineFromText('multilinestring ((10.02 20.01,10.32
23.98,11.92 25.64),(9.55 23.75,15.36 30.11))',1000) 
);

INSERT INTO envelope_test VALUES( 
   'Multipolygon', 
   ST_MPolyFromText('multipolygon (((10.02 20.01,11.92 35.64,25.02
34.15,19.15 33.94,10.02 20.01)),((51.71 21.73,73.36 27.04,71.52
32.87,52.43 31.90,51.71 21.73)))',1000) 
);
The following query lists the subclass name and its envelope. The ST_Envelope() function returns a point, a linestring, or a polygon:
SELECT geotype, ST_Envelope(g1) Envelope 
   FROM envelope_test;


geotype   Point
envelope  1000 POINT (10.02 20.01) 

geotype   Linestring
envelope  1000 LINESTRING (10.01 20.01, 10.01 40.01) 

geotype   Linestring
envelope  1000 POLYGON ((10.02 20.01, 11.92 20.01, 11.92 25.64, 10.02 25.64, 10.02 20.01)) 

geotype   Polygon
envelope  1000 POLYGON ((10.02 20.01, 25.02 20.01, 25.02 35.64, 10.02 35.64, 10.02 20.01)) 

geotype   Multipoint
envelope  1000 POLYGON ((10.02 20.01, 11.92 20.01, 11.92 25.64, 10.02 25.64, 10.02 20.01)) 

geotype   Multilinestring
envelope  1000 LINESTRING (10.01 20.01, 50.01 20.01) 

geotype   Multilinestring
envelope  1000 POLYGON ((9.55 20.01, 15.36 20.01, 15.36 30.11, 9.55 30.11, 9.55 20.01)) 

geotype   Multipolygon
envelope  1000 POLYGON ((10.02 20.01, 73.36 20.01, 73.36 35.64, 10.02 35.64, 10.02 20.01)) 

See also

The SE_BoundingBox() function