Shift and/or scale the span of a bounding box by one or two values
shiftValue(box,{integer,float}) → box
scaleValue(box,{integer,float}) → box
shiftScaleValue(tbox,{integer,float},{integer,float}) → box
SELECT shiftValue(tbox 'TBOXFLOAT XT([1.5, 2.5],[2001-01-01,2001-01-02])', 1.0); -- TBOXFLOAT XT([2.5, 3.5],[2001-01-01, 2001-01-02]) SELECT scaleValue(tbox 'TBOXFLOAT XT([1.5, 2.5],[2001-01-01,2001-01-02])', 2.0); -- TBOXFLOAT XT([1.5, 3.5],[2001-01-01, 2001-01-02]) SELECT shiftScaleValue(tbox 'TBOXFLOAT XT([1.5, 2.5],[2001-01-01,2001-01-02])', 2.0, 3.0); -- TBOXFLOAT XT([3.5, 6.5],[2001-01-01, 2001-01-02])
Shift and/or scale the span or the period of the bounding box to a value or interval
shiftTime(box,interval) → box
scaleTime(box,interval) → box
shiftScaleTime(box,interval,interval) → box
For scaling, if the width or the time span of the period is zero (that is, the lower and upper bound are equal), the result is the box. The given value or interval must be strictly greater than zero.
SELECT shiftTime(tbox 'TBOXFLOAT XT([1.5, 2.5],[2001-01-01,2001-01-02])', interval '1 day'); -- TBOXFLOAT XT([1.5, 2.5],[2001-01-02, 2001-01-03]) SELECT shiftTime(stbox 'STBOX T([2001-01-01,2001-01-02])', interval '-1 day'); -- STBOX T([2001-12-31, 2001-01-01]) SELECT shiftTime(stbox 'STBOX ZT(((1,1,1),(2,2,2)),[2001-01-01,2001-01-02])', interval '1 day'); -- STBOX ZT(((1,1,1),(2,2,2)),[2001-01-02, 2001-01-03]) SELECT scaleTime(tbox 'TBOXFLOAT XT([1.5, 2.5],[2001-01-01,2001-01-02])', interval '2 days'); -- TBOXFLOAT XT([1.5, 2.5],[2001-01-01, 2001-01-03]) SELECT scaleTime(stbox 'STBOX ZT(((1,1,1),(2,2,2)),[2001-01-01,2001-01-02])', interval '1 hour'); -- STBOX ZT(((1,1,1),(2,2,2)),[2001-01-01 00:00:00, 2001-01-01 01:00:00]) SELECT scaleTime(stbox 'STBOX ZT(((1,1,1),(2,2,2)),[2001-01-01,2001-01-02])', interval '-1 day'); -- ERROR: The interval must be positive: -1 days SELECT shiftScaleTime(tbox 'TBOXFLOAT XT([1.5, 2.5],[2001-01-01,2001-01-02])', interval '1 day', interval '3 days'); -- TBOXFLOAT XT([1.5, 2.5],[2001-01-02, 2001-01-05]) SELECT shiftScaleTime(stbox 'STBOX ZT(((1,1,1),(2,2,2)),[2001-01-01,2001-01-02])', interval '1 hour', interval '3 hours'); -- STBOX ZT(((1,1,1),(2,2,2)),[2001-01-01 01:00:00, 2001-01-01 04:00:00])
Return the spatial dimension of the bounding box, removing the temporal dimension if any
getSpace(stbox) → stbox
SELECT getSpace(stbox 'STBOX ZT(((1,1,1),(2,2,2)),[2001-01-01,2001-01-03])'); -- STBOX Z((1,1,1),(2,2,2))
The functions given next expand the bounding boxes on the value and the time dimension or set the precision of the value dimension. These functions raise an error if the corresponding dimension is not present.
Expand the numeric, spatial, or temporal dimension of a bounding box by a value or an interval
expandValue(tbox,{integer,float}) → tbox
expandSpace(stbox,float) → stbox
expandTime(box,interval) → box
The function returns NULL if the value or interval given as second argument is negative and the span resulting from shifting the bounds with the argument is empty.
SELECT expandValue(tbox 'TBOXFLOAT XT((1,2),[2001-01-01,2001-01-03])', 1.0); -- TBOXFLOAT XT((0,3),[2001-01-01,2001-01-03]) SELECT expandValue(tbox 'TBOXFLOAT XT((1,2),[2001-01-01,2001-01-03])', -1.0); -- NULL SELECT expandValue(tbox 'TBOX T([2001-01-01,2001-01-03))', 1); -- The box must have value dimension
SELECT expandSpace(stbox 'STBOX ZT(((1,1,1),(2,2,2)),[2001-01-01,2001-01-03])', 1); -- STBOX ZT(((0,0,0),(3,3,3)),[2001-01-01,2001-01-03]) SELECT expandSpace(stbox 'STBOX T([2001-01-01,2001-01-03))', 1); -- The box must have space dimension
SELECT expandTime(tbox 'TBOXFLOAT XT((1,2),[2001-01-01,2001-01-03])', interval '1 day'); -- TBOXFLOAT XT((1,2),[2000-12-31,2001-01-04]) SELECT expandTime(stbox 'STBOX ZT(((1,1,1),(2,2,2)),[2001-01-01,2001-01-03])', interval '-1 day'); -- STBOX ZT(((1,1,1),(2,2,2)),[2001-01-02,2001-01-02]) SELECT expandTime(tbox 'TBOX XT((1,2),[2001-01-01,2001-01-03])', interval '-2 days'); -- NULL
Round the value or the coordinates of the bounding box to a number of decimal places
round(box,integer=0) → box
SELECT round(tbox 'TBOXFLOAT XT((1.12345,2.12345),[2001-01-01,2001-01-02])', 2); -- TBOXFLOAT XT((1.12,2.12),[2001-01-01, 2001-01-02]) SELECT round(stbox 'STBOX XT(((1.12345, 1.12345),(2.12345, 2.12345)), [2001-01-01,2001-01-02])', 2); -- STBOX XT(((1.12,1.12),(2.12,2.12)),[2001-01-01, 2001-01-02]) SELECT round(tstzspan '[2000-01-01, 2001-01-02]'::tbox); -- The tbox must have X dimension