Bounding Box tpcbox

The tpcbox type is the spatiotemporal bounding box for the temporal point-cloud types. It mirrors the structure of stbox (see Chapter 3, Bounding Box Types) — same X/Y/Z/T axes, same flag bits for which dimensions are present — and adds a single field: the pcid. Two tpcbox values with different pcid values are never considered to overlap, contain, equal, or be adjacent to each other, regardless of their geometric or temporal extent.

Carrying the pcid through bounding-box arithmetic guarantees that bounding-box pruning never drops a row whose schema differs from the query's schema, and never returns a hit across mismatched schemas.

Constructors

  • Construct a tpcbox from explicit X/Y/Z/T bounds and a pcid

    tpcbox(xmin,ymin,xmax,ymax,pcid,srid=0) → tpcbox

    tpcbox_z(xmin,ymin,zmin,xmax,ymax,zmax,pcid,srid=0) → tpcbox

    tpcbox_t(period,pcid) → tpcbox

    tpcbox_xt(xmin,ymin,xmax,ymax,period,pcid,srid=0) → tpcbox

    tpcbox_zt(xmin,ymin,zmin,xmax,ymax,zmax,period,pcid,srid=0) → tpcbox

    SELECT tpcbox(0, 0, 10, 10, 1, 0);
    -- TPCBOX X(0, 0), (10, 10) PCID=1
    SELECT tpcbox_zt(0, 0, 0, 10, 10, 10, tstzspan '[2024-01-01, 2024-01-02]', 1, 0);
    

Conversions

  • Convert a pcpoint to a degenerate (zero-extent) tpcbox; SRID and pcid come from the schema

    tpcbox(pcpoint) → tpcbox

    SELECT tpcbox(PC_MakePoint(1, ARRAY[10.0, 20.0, 30.0]));
    -- TPCBOX Z(10, 20, 30), (10, 20, 30) PCID=1
    
  • Convert a pcpatch to a tpcbox using the patch's embedded 2D PCBOUNDS; the second form takes an explicit SRID instead of looking it up from the schema

    tpcbox(pcpatch) → tpcbox

    tpcbox(pcpatch,integer) → tpcbox

    SELECT tpcbox(PC_Patch(PC_MakePoint(1, ARRAY[10.0, 20.0, 30.0])));
    

Accessors

  • Return whether a tpcbox has the X/Y, Z, or T dimensions set

    hasX(tpcbox) → boolean

    hasZ(tpcbox) → boolean

    hasT(tpcbox) → boolean

    WITH b AS (SELECT tpcbox(0, 0, 10, 10, 1, 0) AS b)
      SELECT hasX(b), hasZ(b) FROM b;
    -- t | f
    
  • Return a coordinate bound, NULL if the corresponding dimension is absent

    xmin(tpcbox) → float

    xmax(tpcbox) → float

    ymin(tpcbox) → float

    ymax(tpcbox) → float

    zmin(tpcbox) → float

    zmax(tpcbox) → float

    WITH b AS (SELECT tpcbox(0, 0, 10, 10, 1, 0) AS b)
      SELECT xmin(b), xmax(b) FROM b;
    -- 0 | 10
    
  • Return a temporal bound, NULL if the box has no T dimension

    tmin(tpcbox) → timestamptz

    tmax(tpcbox) → timestamptz

    SELECT tmin(tpcbox_t(tstzspan '[2024-01-01, 2024-01-02]', 1));
    -- 2024-01-01 00:00:00+00
    
  • Return the schema id and SRID

    pcid(tpcbox) → integer

    SRID(tpcbox) → integer

    WITH b AS (SELECT tpcbox(0, 0, 10, 10, 7, 4326) AS b)
      SELECT pcid(b), SRID(b) FROM b;
    -- 7 | 4326
    

Transformations

  • Return a tpcbox with coordinates rounded to a given number of decimal digits

    round(tpcbox,integer=0) → tpcbox

    SELECT round(tpcbox(0.123456, 1.234567, 2.345678, 3.456789, 1, 0), 2);
    -- TPCBOX X(0.12, 1.23), (2.35, 3.46) PCID=1
    
  • Return a tpcbox with the SRID overwritten. Does not reproject coordinates — for that, project the underlying tpcpoint first and take the bbox of the result

    setSRID(tpcbox,integer) → tpcbox

    SELECT SRID(setSRID(tpcbox(0, 0, 10, 10, 1, 0), 4326));
    -- 4326
    

Set Operations

  • Return the union of two tpcboxes; both must share the same pcid

    tpcbox_union(tpcbox,tpcbox) → tpcbox

    tpcbox + tpcbox → tpcbox

    SELECT tpcbox(0, 0, 5, 5, 1, 0) + tpcbox(3, 3, 10, 10, 1, 0);
    -- TPCBOX X(0, 0), (10, 10) PCID=1
    
  • Return the intersection of two tpcboxes, NULL if disjoint or pcid mismatch

    tpcbox_intersection(tpcbox,tpcbox) → tpcbox

    tpcbox * tpcbox → tpcbox

    SELECT tpcbox(0, 0, 5, 5, 1, 0) * tpcbox(3, 3, 10, 10, 1, 0);
    -- TPCBOX X(3, 3), (5, 5) PCID=1
    

Note: a generic box-vs-box minus is not provided, mirroring the convention for stbox and tbox: the difference of two boxes is not generally a box.

Topological Operators

All topological operators take two tpcbox values with matching pcid. A pcid mismatch always yields false (not an error) so that index scans behave intuitively.

  • Return true if the first tpcbox contains the second

    tpcbox @> tpcbox → boolean

    SELECT tpcbox(0, 0, 10, 10, 1, 0) @> tpcbox(2, 2, 8, 8, 1, 0);
    -- t
    
  • Return true if the first tpcbox is contained in the second

    tpcbox <@ tpcbox → boolean

    SELECT tpcbox(2, 2, 8, 8, 1, 0) <@ tpcbox(0, 0, 10, 10, 1, 0);
    -- t
    
  • Return true if two tpcboxes overlap

    tpcbox && tpcbox → boolean

    SELECT tpcbox(0, 0, 5, 5, 1, 0) && tpcbox(3, 3, 10, 10, 1, 0);  -- t
    SELECT tpcbox(0, 0, 5, 5, 1, 0) && tpcbox(0, 0, 5, 5, 2, 0);  -- f (pcid mismatch)
    
  • Return true if two tpcboxes are exactly equal

    tpcbox ~= tpcbox → boolean

  • Return true if two tpcboxes are adjacent (share a boundary)

    tpcbox -|- tpcbox → boolean

Position Operators

Sixteen axis-aligned position predicates, parallel to those on stbox. Each tests strict-or-overlap relationship along one axis. All require matching pcid; mismatch returns false. Z-axis predicates require both boxes to have a Z dimension; T-axis predicates require both to have a T dimension.

  • Test the X-axis ordering of two tpcboxes

    tpcbox << tpcbox → boolean (strictly left)

    tpcbox &< tpcbox → boolean (does not extend right)

    tpcbox >> tpcbox → boolean (strictly right)

    tpcbox &> tpcbox → boolean (does not extend left)

  • Test the Y-axis ordering of two tpcboxes

    tpcbox <<| tpcbox → boolean (strictly below)

    tpcbox &<| tpcbox → boolean (does not extend above)

    tpcbox |>> tpcbox → boolean (strictly above)

    tpcbox |&> tpcbox → boolean (does not extend below)

  • Test the Z-axis ordering of two tpcboxes (returns false if either lacks Z)

    tpcbox <</ tpcbox → boolean (strictly in front)

    tpcbox &</ tpcbox → boolean (does not extend behind)

    tpcbox />> tpcbox → boolean (strictly behind)

    tpcbox /&> tpcbox → boolean (does not extend in front)

  • Test the time-axis ordering of two tpcboxes (returns false if either lacks T)

    tpcbox <<# tpcbox → boolean (strictly before)

    tpcbox &<# tpcbox → boolean (does not extend after)

    tpcbox #>> tpcbox → boolean (strictly after)

    tpcbox #&> tpcbox → boolean (does not extend before)

Comparisons

  • Compare two tpcboxes; total order over the canonical encoding (pcid, srid, flags, period, then spatial bounds in XYZ-min/max order)

    tpcbox = tpcbox → boolean

    tpcbox <> tpcbox → boolean

    tpcbox < tpcbox → boolean

    tpcbox <= tpcbox → boolean

    tpcbox > tpcbox → boolean

    tpcbox >= tpcbox → boolean