Constructs a boxndf bounding box from explicit coordinate and timestamp bounds. Use these functions to define a search region for spatial index queries or spatiotemporal range filters.
Syntax
-- Single-axis (elevation)
boxndf ST_MakeBoxZ(float8 zmin, float8 zmax);
-- Single-axis (time)
boxndf ST_MakeBoxT(timestamp tmin, timestamp tmax);
-- 2D spatial
boxndf ST_MakeBox2D(float8 xmin, float8 ymin, float8 xmax, float8 ymax);
-- 2D spatial + time
boxndf ST_MakeBox2DT(float8 xmin, float8 ymin, timestamp tmin, float8 xmax, float8 ymax, timestamp tmax);
-- 3D spatial
boxndf ST_MakeBox3D(float8 xmin, float8 ymin, float8 zmin, float8 xmax, float8 ymax, float8 zmax);
-- 3D spatial + time
boxndf ST_MakeBox3DT(float8 xmin, float8 ymin, float8 zmin, timestamp tmin, float8 xmax, float8 ymax, float8 zmax, timestamp tmax);Parameters
| Parameter | Description |
|---|---|
xmin | Lower bound on the x-axis. |
xmax | Upper bound on the x-axis. |
ymin | Lower bound on the y-axis. |
ymax | Upper bound on the y-axis. |
zmin | Lower bound on the z-axis. |
zmax | Upper bound on the z-axis. |
tmin | Lower bound on the t-axis (earliest timestamp). |
tmax | Upper bound on the t-axis (latest timestamp). |
The min parameters define the lower-left corner of the bounding box; the max parameters define the upper-right corner.
Return value
All variants return a boxndf value.
Because boxndf stores coordinates as float8 (64-bit floating-point), the returned bounding box may be slightly larger than the values you pass in: the lower bound may be slightly smaller than specified, and the upper bound may be slightly larger. This is expected behavior — spatial index lookups remain correct.
Examples
Create a 2D bounding box
The following example creates a 2D bounding box and returns it in BOX2D format.
SELECT ST_MakeBox2D(0, 0, 3, 3); st_makebox2d
----------------
BOX2D(0 0,3 3)Create a 3D spatiotemporal bounding box
The following example creates a bounding box with three spatial dimensions and a time range, then returns it in BOX3DT format. The output timestamps show the float rounding effect described above.
SELECT ST_MakeBox3DT(0, 0, 3, '2000-01-01 00:00:03'::timestamp, 2, 5, 4, '2000-01-01 02:46:40'::timestamp); st_makebox3dt
---------------------------------------------------------------------------
BOX3DT(0 0 3 2000-01-01 00:00:02.999999,2 5 4 2000-01-01 02:46:40.000476)
(1 row)