ST_Envelope
Returns the minimum bounding box (envelope) of a geometry.
Syntax
ST_Envelope(geometry)
Parameters
| Parameter | Type | Description |
|---|---|---|
| geometry | Geometry | Input geometry |
Returns
| Type | Description |
|---|---|
| Binary (WKB) | Bounding box as WKB polygon with geoarrow.wkb metadata |
Examples
Envelope of Polygon
SELECT ST_Envelope(ST_GeomFromText('POLYGON((0 0, 3 0, 3 2, 1 4, 0 2, 0 0))'));
-- Returns: POLYGON((0 0, 3 0, 3 4, 0 4, 0 0))
Envelope of LineString
SELECT ST_Envelope(ST_GeomFromText('LINESTRING(0 0, 1 1, 2 0)'));
-- Returns: POLYGON((0 0, 2 0, 2 1, 0 1, 0 0))
Calculate Extent of Features
SELECT category, ST_Envelope(ST_Union(geom)) as extent
FROM features
GROUP BY category;
Pre-filter with Envelope
SELECT * FROM detailed_features
WHERE ST_Intersects(ST_Envelope(geom), search_box);
Notes
- Returns the axis-aligned minimum bounding rectangle
- For Points, returns a polygon with zero area
- For horizontal/vertical lines, returns a degenerate polygon
- Useful for spatial indexing and quick intersection tests
- Envelope intersection is faster than full geometry intersection
See Also
- ST_ConvexHull - Tighter bounding shape
- ST_Centroid - Center point
- ST_Area - Calculate area