A raquet value is self-describing: the accessors below read back the georeferencing and layout it carries, so a tile packaged with the raquet constructor or decoded with raquetRead can be inspected without keeping the loose columns it was built from.
Tiles also support the full set of comparison operators. The ordering is total and is defined on the QUADBIN cell first, then the pixel type, the width, the height, and finally the pixel bytes; it is meant for indexing and deduplication rather than for a spatial interpretation. A default btree operator class makes ORDER BY, DISTINCT and merge joins work on raquet columns, and a default hash operator class enables hash joins and hash aggregation.
Return the QUADBIN cell of a Raquet tile
quadbin(raquet) → bigint
SELECT quadbin(raquet('\x01020304'::bytea, 2, 2, 5193776270265024512, 'UINT8'));
-- 5193776270265024512
Return the width in pixels of a Raquet tile
width(raquet) → integer
SELECT width(raquet('\x01020304'::bytea, 2, 2, 5193776270265024512, 'UINT8'));
-- 2
Return the height in pixels of a Raquet tile
height(raquet) → integer
SELECT height(raquet('\x01020304'::bytea, 2, 2, 5193776270265024512, 'UINT8'));
-- 2
Return the nodata sentinel value of a Raquet tile
nodata(raquet) → float8
SELECT nodata(raquet('\x01020304'::bytea, 2, 2,
5193776270265024512, 'UINT8', 255));
-- 255
-- The sentinel defaults to 0 when the constructor omits it.
SELECT nodata(raquet('\x01020304'::bytea, 2, 2, 5193776270265024512, 'UINT8'));
-- 0
Return the name of the pixel data type of a Raquet tile
pixtype(raquet) → text
The returned name is the one the constructors accept, that is, one of UINT8, INT16, INT32, FLOAT32, or FLOAT64.
-- Read back the layout of a packaged tile
SELECT quadbin(tile), width(tile), height(tile), pixtype(tile), nodata(tile)
FROM (SELECT raquet('\x01020304'::bytea, 2, 2, 5193776270265024512, 'UINT8') AS tile) t;
-- 5193776270265024512 | 2 | 2 | UINT8 | 0
Convert a Raquet tile into a spatiotemporal box
stbox(raquet) → stbox
Returns the tile footprint: the longitude and latitude envelope of its QUADBIN cell, in SRID 4326 and without a time dimension. The footprint follows from the cell alone, so tiles differing in pixels, dimensions or pixel type share it. The conversion is also available as a cast.
-- The footprint of a tile covering the north-eastern quadrant at zoom 1
SELECT round(stbox(raquet('\x01020304'::bytea, 2, 2, 5193776270265024512,
'UINT8')), 6);
-- SRID=4326;STBOX X((0,0),(180,85.051129))
-- Keep the tiles whose footprint overlaps a region of interest
SELECT * FROM elevation_tiles
WHERE tile::stbox && stbox 'SRID=4326;STBOX X((0,0),(30,30))';
The footprint carries the stbox operators, aggregates and operator classes, so a tile table is searched by spatial overlap at any zoom level rather than by an equality test on the QUADBIN cell at a single fixed one. Indexing the conversion gives the tile table a spatial index, and the extent of a set of tiles is the extent of their footprints.
-- A spatial index over the tile footprints CREATE INDEX elevation_tiles_gist ON elevation_tiles USING gist (stbox(tile)); CREATE INDEX elevation_tiles_spgist ON elevation_tiles USING spgist (stbox(tile)); -- The extent covered by a set of tiles SELECT extent(stbox(tile)) FROM elevation_tiles; -- Tiles a trajectory passes through, at whatever zoom levels the table holds SELECT t.tripid, r.tile FROM trips t, elevation_tiles r WHERE stbox(r.tile) && stbox(t.trip);
Compare two Raquet tiles
raquet = raquet → boolean
raquet <> raquet → boolean
raquet < raquet → boolean
raquet <= raquet → boolean
raquet >= raquet → boolean
raquet > raquet → boolean
The functions backing these operators are eq, ne, lt, le, ge and gt, together with cmp(raquet,raquet) → integer, which returns -1, 0, or 1.
-- Two tiles with the same cell, layout and pixels are equal
SELECT raquet('\x0102'::bytea, 2, 1, 5193776270265024512, 'UINT8') =
raquet('\x0102'::bytea, 2, 1, 5193776270265024512, 'UINT8');
-- true
-- Deduplicate tiles, which the btree and hash operator classes support
SELECT DISTINCT tile FROM elevation_tiles;