Returns the bounding box of a geometry or trajectory, optionally constrained to a time range.
Syntax
boxndf ST_MakeBox(geometry geom);
boxndf ST_MakeBox(trajectory traj);
boxndf ST_MakeBox(geometry geom, timestamp ts, timestamp te);
boxndf ST_MakeBox(trajectory traj, timestamp ts, timestamp te);
boxndf ST_MakeBox(timestamp ts, timestamp te);Parameters
| Parameter | Description |
|---|---|
geom | The geometry whose bounding box you want to query. |
traj | The trajectory whose bounding box you want to query. |
ts | The start of the time range. |
te | The end of the time range. |
Description
A bounding box is the minimal multi-dimensional rectangle that contains a spatio-temporal object.
The function behavior depends on which overload you use:
Geometry only —
ST_MakeBox(geometry geom): Returns the spatial bounding box based on the geometry's dimensions (2D or 3D).Geometry + time range —
ST_MakeBox(geometry geom, timestamp ts, timestamp te): Returns the bounding box of the geometry over the specified time range.Trajectory only —
ST_MakeBox(trajectory traj): Returns the bounding box of the complete trajectory.Trajectory + time range —
ST_MakeBox(trajectory traj, timestamp ts, timestamp te): Returns the bounding box of the sub-trajectory over the time range.Time range only —
ST_MakeBox(timestamp ts, timestamp te): Returns a bounding box for the specified time range.
Note: Bounding boxes use the FLOAT data type. The returned box may be slightly larger than the exact input values — the lower bound may be slightly smaller than the actual lower bound, and the upper bound may be slightly larger than the actual upper bound.
Examples
Geometry bounding box
The following examples compute the bounding box of a polygon, with and without a time range.
WITH geom AS (
SELECT (
'POLYGON((12.7243236691148 4.35238368367118,12.9102992732078 1.49748113937676,' ||
'12.5926592946053 1.67643963359296,12.0197574747333 3.19258554889152,' ||
'12.7243236691148 4.35238368367118))'
)::geometry a
)
SELECT
-- Spatial bounding box only (BOX2D)
ST_MakeBox(a),
-- Spatio-temporal bounding box with time range (BOX2DT)
ST_MakeBox(a, '2000-01-01 00:00:10'::timestamp, '2000-01-01 02:13:20'::timestamp)
FROM geom;Expected output:
st_makebox | st_makebox
----------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------
BOX2D(12.0197572708 1.49748110771,12.9102993011 4.35238409042) | BOX2DT(12.0197572708 1.49748110771 2000-01-01 00:00:09.999999,12.9102993011 4.35238409042 2000-01-01 02:13:20.000381)Trajectory bounding box
The following examples compute the bounding box of a trajectory, with and without a time range.
WITH traj AS (
SELECT ST_makeTrajectory(
'STPOINT',
'LINESTRING(0 0, 50 50, 100 100)'::geometry,
tsrange('2000-01-01 00:00:00'::timestamp, '2000-01-01 00:01:40'::timestamp),
'{"leafcount":3,"attributes":{"velocity":{"type":"integer","length":2,"nullable":true,"value":[120,130,140]},"accuracy":{"type":"float","length":4,"nullable":false,"value":[120,130,140]},"bearing":{"type":"float","length":8,"nullable":false,"value":[120,130,140]},"acceleration":{"type":"string","length":20,"nullable":true,"value":["120","130","140"]},"active":{"type":"timestamp","nullable":false,"value":["Fri Jan 01 11:35:00 2010","Fri Jan 01 12:35:00 2010","Fri Jan 01 13:30:00 2010"]}},"events":[{"2":"Fri Jan 02 15:00:00 2010"},{"3":"Fri Jan 02 15:30:00 2010"}]}'
) a
)
SELECT
-- Full trajectory bounding box (BOX2DT)
ST_MakeBox(a),
-- Sub-trajectory bounding box within time range (BOX2DT)
ST_MakeBox(a, '1999-12-31 23:00:00'::timestamp, '2000-01-01 00:00:30'::timestamp)
FROM traj;Expected output:
st_makebox | st_makebox
-------------------------------------------------------------+------------------------------------------------------------------
BOX2DT(0 0 2000-01-01 00:00:00,100 100 2000-01-01 00:01:40) | BOX2DT(0 0 2000-01-01 00:00:00,30 30 2000-01-01 00:00:30.000001)