Chapter 3. Bounding Box Types

Table of Contents

Input and Output
Constructors
Conversions
Accessors
Transformations
Spatial Reference System
Split Functions
Set Operations
Bounding Box Operations
Topological Operations
Position Operations
Comparisons
Aggregations
Indexing

We present next the functions and operators for bounding box types. These functions and operators are polimorhic, that is, their argumentos can be of various types and their result type may depend on the type of the arguments. To express this in the signature of the operators, we use the following notation:

Input and Output

MobilityDB generalizes Open Geospatial Consortium's Well-Known Text (WKT) and Well-Known Binary (WKB) input and output format for all temporal types. We present next the functions for input and output box types.

A tbox is composed of a numeric and/or time dimensions. For each dimension, a span given, that is, either an intspan or a floatspan for the value dimension and a tstzspan for the time dimension. Examples of input of tbox values are as follows:

-- Both value and time dimensions
SELECT tbox 'TBOXINT XT([1,3),[2001-01-01,2001-01-02])';
SELECT tbox 'TBOXFLOAT XT([1.5,2.5],[2001-01-01,2001-01-02])';
-- Only value dimension
SELECT tbox 'TBOXINT X([1,3))';
SELECT tbox 'TBOXFLOAT X((1.5,2.5))';
-- Only time dimension
SELECT tbox 'TBOX T((2001-01-01,2001-01-02))';

An stbox is composed of a spatial and/or time dimensions, where the coordinates of the spatial dimension may be 2D or 3D. For the time dimension a tstzspan is given and for the spatial dimension minimum and maximum coordinate values are given, where the latter may be Cartesian (planar) or geodetic (spherical). The SRID of the coordinates may be specified; if it is not the case, a value of 0 (unknown) and 4326 (corresponding to WGS84) is assumed, respectively, for planar and geodetic boxes. Geodetic boxes always have a Z dimension to account for the curvature of the underlying sphere or spheroid. Examples of input of stbox values are as follows:

-- Only value dimension with X and Y coordinates
SELECT stbox 'STBOX X((1.0,2.0),(1.0,2.0))';
-- Only value dimension with X, Y, and Z coordinates
SELECT stbox 'STBOX Z((1.0,2.0,3.0),(1.0,2.0,3.0))';
-- Both value (with X and Y coordinates) and time dimensions
SELECT stbox 'STBOX XT(((1.0,2.0),(1.0,2.0)),[2001-01-03,2001-01-03])';
-- Both value (with X, Y, and Z coordinates) and time dimensions
SELECT stbox 'STBOX ZT(((1.0,2.0,3.0),(1.0,2.0,3.0)),[2001-01-01,2001-01-03])';
-- Only time dimension
SELECT stbox 'STBOX T([2001-01-03,2001-01-03])';
-- Only value dimension with X, Y, and Z geodetic coordinates
SELECT stbox 'GEODSTBOX Z((1.0,2.0,3.0),(1.0,2.0,3.0))';
-- Both value (with X, Y and Z geodetic coordinates) and time dimension
SELECT stbox 'GEODSTBOX ZT(((1.0,2.0,3.0),(1.0,2.0,3.0)),[2001-01-04,2001-01-04])';
-- Only time dimension for geodetic box
SELECT stbox 'GEODSTBOX T([2001-01-03,2001-01-03])';
-- SRID is given
SELECT stbox 'SRID=5676;STBOX XT(((1.0,2.0),(1.0,2.0)),[2001-01-04,2001-01-04])';
SELECT stbox 'SRID=4326;GEODSTBOX Z((1.0,2.0,3.0),(1.0,2.0,3.0))';

We give next the functions for input and output of box types in Well-Known Text and Well-Known Binary format.

  • Return the Well-Known Text (WKT) representation

    asText(box,maxdecdigits=15) → text

    The maxdecdigits argument can be used to set the maximum number of decimal places in the output of floating point values (default 15).

    SELECT asText(tbox 'TBOXFLOAT XT([1.123456789,2.123456789),[2001-01-01,2001-01-02))', 3);
    -- TBOXFLOAT XT([1.123, 2.123),[2001-01-01 00:00:00+01, 2001-01-02 00:00:00+01))
    SELECT asText(stbox 'STBOX Z((1.55,1.55,1.55),(2.55,2.55,2.55))', 0);
    -- STBOX Z((2,2,2),(3,3,3))
    
  • Return the Well-Known Binary (WKB) representation

    asBinary(box,endian text='') → bytea

    The result is encoded using either the little-endian (NDR) or the big-endian (XDR) encoding. If no encoding is specified, then the encoding of the machine is used.

    SELECT asBinary(tbox 'TBOXFLOAT XT([1,2),[2001-01-01,2001-01-02))');
    -- \x0103270001009c57d3c11c000000fc2ef1d51c00000d0001000000000000f03f0000000000000040
    SELECT asBinary(tbox 'TBOXFLOAT XT([1,2),[2001-01-01,2001-01-02))', 'XDR');
    -- \x000300270100001cc1d3579c0000001cd5f12efc00000d013ff00000000000004000000000000000
    SELECT asBinary(stbox 'STBOX X((1,1),(2,2))');
    -- \x0101000000000000f03f0000000000000040000000000000f03f0000000000000040
    
  • Return the Hexadecimal Well-Known Binary (HexWKB) representation as text

    asHexWKB(box,endian text='') → text

    The result is encoded using either the little-endian (NDR) or the big-endian (XDR) encoding. If no encoding is specified, then the encoding of the machine is used.

    SELECT asHexWKB(tbox 'TBOXFLOAT XT([1,2),[2001-01-01,2001-01-02))');
    -- 0103270001009C57D3C11C000000FC2EF1D51C00000D0001000000000000F03F0000000000000040
    SELECT asHexWKB(tbox 'TBOXFLOAT XT([1,2)[2001-01-01,2001-01-02))', 'XDR');
    -- 000300270100001CC1D3579C0000001CD5F12EFC00000D013FF00000000000004000000000000000
    SELECT asHexWKB(stbox 'STBOX X((1,1),(2,2))');
    -- 0101000000000000F03F0000000000000040000000000000F03F0000000000000040
    
  • Input from a Well-Known Binary (WKB) representation

    tboxFromBinary(bytea) → tbox

    stboxFromBinary(bytea) → stbox

    SELECT tboxFromBinary(
      '\x0103270001009c57d3c11c000000fc2ef1d51c00000d0001000000000000f03f0000000000000040');
    -- TBOXFLOAT XT([1,2),[2001-01-01,2001-01-02))
    SELECT stboxFromBinary(
      '\x0101000000000000f03f0000000000000040000000000000f03f0000000000000040');
    --  STBOX X((1,1),(2,2))
    
  • Input from an Hexadecimal Well-Known Binary (HexWKB) representation

    tboxFromHexWKB(text) → tbox

    stboxFromHexWKB(text) → stbox

    SELECT tboxFromHexWKB(
      '0103270001009C57D3C11C000000FC2EF1D51C00000D0001000000000000F03F0000000000000040');
    -- TBOXFLOAT XT([1,2),[2001-01-01,2001-01-02)))
    SELECT stboxFromHexWKB(
      '0101000000000000F03F0000000000000040000000000000F03F0000000000000040');
    -- STBOX X((1,1),(2,2))