QUADBIN is built on the slippy-map (Web-Mercator) tile scheme, so a cell maps directly to a tile coordinate triple (x,y,z) and to the base-4 quadkey string tile servers use. These conversions are the QUADBIN-specific bridge to the tiling ecosystem, and have no counterpart in a hexagonal or a spherical-quadrilateral grid.
Return whether a value is a structurally valid QUADBIN identifier
isValidIndex(quadbin) → boolean
Correct header tag and resolution field. The input of the quadbin type raises an error on any other value, so every value of the type is a valid index, while isValidCell answers whether the index is a data cell: the index 504b5fffffffffff carries mode 2.
SELECT isValidIndex(quadbin '480fffffffffffff'); -- t SELECT isValidIndex(quadbin '504b5fffffffffff'); -- t
Return the neighbouring cell at the same resolution in the given direction
quadbinCellSibling(quadbin,text) → quadbin
up / down / left / right, in any case, as cell_sibling of the CARTO reference reads the direction; another direction raises an error. The answer is NULL for a sibling beyond an edge of the grid, which has no cell there: a column does not wrap at the antimeridian and a row does not cross a pole.
SELECT quadbinCellSibling( quadbinCellSibling(quadbin '48427fffffffffff', 'right'), 'left') = quadbin '48427fffffffffff'; -- t
Emit the base-4 slippy-tile quadkey string of a cell
quadbinCellToQuadkey(quadbin) → text tquadbinCellToQuadkey(tquadbin) → ttext
One digit per zoom level, most significant first, the resolution-0 world cell mapping to the empty string. The static form takes a single quadbin, the temporal form returning the quadkey of each cell in a trajectory as a ttext.
SELECT quadbinCellToQuadkey(quadbin '480fffffffffffff'); -- (empty string) SELECT quadbinCellToQuadkey(quadbin '48427fffffffffff'); -- 0213 SELECT quadbinCellToQuadkey(quadbin '48a6227affffffff'); -- 1202021322
Return the temporal grid distance between two temporal QUADBIN cells
tquadbinGridDistance(tquadbin,tquadbin) → tbigint tquadbin <-> tquadbin → tbigint
The grid distance of two cells of the same zoom is the smallest radius whose gridDisk around one holds the other, the larger of the differences of their tile columns and rows. The grid has no cell beyond its edges, so the cells at the two ends of a row are a whole row apart. Equivalently, the <-> operator returns the same distance.
SELECT asText(tquadbinGridDistance( tquadbin(quadbinTileToCell(1, 1, 3), tstzspan '[2001-01-01, 2001-01-03]'), tquadbin(quadbinTileToCell(4, 2, 3), tstzspan '[2001-01-02, 2001-01-04]'))); -- [3@2001-01-02, 3@2001-01-03] SELECT tquadbin(quadbinTileToCell(0, 3, 3), timestamptz '2001-01-01') <-> tquadbin(quadbinTileToCell(7, 3, 3), timestamptz '2001-01-01'); -- 7@2001-01-01
Decompose a cell back into its tile coordinate triple, returned as an integer array holding x, then y, then z
quadbinCellToTile(quadbin) → integer[]
It is the inverse of the tile constructor
SELECT quadbinCellToTile(quadbin '480fffffffffffff');
-- {0,0,0}
SELECT quadbinCellToTile(quadbin '48a6227affffffff');
-- {524,343,10}
Build a cell from slippy-map tile coordinates: column x, row y, and zoom z
quadbinTileToCell(integer,integer,integer) → quadbin
SELECT quadbinTileToCell(0, 0, 0) = quadbin '480fffffffffffff'; -- t SELECT quadbinTileToCell(3, 5, 4) = quadbin '48427fffffffffff'; -- t SELECT quadbinTileToCell(524, 343, 10) = quadbin '48a6227affffffff'; -- t