The operations below have no H3 or QUADBIN analogue. They are stated on a static s2cell, since a cell identifier answers them without reference to time; the shared operations the sections above state apply to a ts2cell through the tcell notation.
Return the cube face in 0 to 5 an S2 cell sits on
s2GetFace(s2cell) → integer
S2 projects the sphere onto the six faces of a circumscribed cube and lays a Hilbert curve on each, so the face is the first three bits of the identifier and two cells on different faces share no ancestor.
SELECT s2GetFace(s2cell '47c3c3'); -- 2 SELECT s2GetFace(geoToS2Cell(geography 'SRID=4326;Point(-122.4 37.8)', 10)); -- 4
Convert between an S2 cell and its token, the form the S2 libraries publish
s2CellToToken(s2cell) → text s2TokenToCell(text) → s2cell ts2CellToToken(ts2cell) → ttext
A token is the identifier in hexadecimal with its trailing zeros removed, so a coarse cell reads shorter than a fine one and the text sorts as the identifier does.
SELECT s2CellToToken(s2cell '47c3c3');
-- 47c3c3
SELECT s2TokenToCell('47c3c3');
-- 47c3c3
SELECT asText(ts2CellToToken(ts2cell '47c3c3@2001-01-01'));
-- "47c3c3"@2001-01-01
Return the temporal grid distance between two temporal S2 cells
ts2GridDistance(ts2cell,ts2cell) → tbigint ts2cell <-> ts2cell → tbigint
The grid distance of two cells of the same level is the number of steps between edge neighbours, those s2EdgeNeighbors returns, from one to the other, across the edges of the cube faces as within a face. Two cells on opposite faces are a path around the cube apart. Equivalently, the <-> operator returns the same distance.
SELECT asText(ts2GridDistance(
ts2cell(s2cell '47c3c', tstzspan '[2001-01-01, 2001-01-03]'),
ts2cell(s2cell '47c34', tstzspan '[2001-01-02, 2001-01-04]')));
-- [1@2001-01-02, 1@2001-01-03]
SELECT ts2cell(geoToS2Cell(geography 'Point(0 0)', 30),
timestamptz '2001-01-01') <->
ts2cell(geoToS2Cell(geography 'Point(180 0)', 30),
timestamptz '2001-01-01');
-- 2147483648@2001-01-01
Return the level of the deepest cell containing two S2 cells
s2CommonAncestorLevel(s2cell,s2cell) → integer
Two cells on different cube faces are contained by no cell, and the function answers -1 for them.
SELECT s2CommonAncestorLevel(s2cell '47c3c3', s2cell '47c4'); -- 5 SELECT s2CommonAncestorLevel(s2cell '47c3c3', s2cell '808581'); -- -1
Return true if the first S2 cell contains the second one
s2CellContains(s2cell,s2cell) → boolean
SELECT s2CellContains(s2cell '47c4', s2cell '47c3c3'); -- t
Return the first and the last leaf cell an S2 cell contains
s2RangeMin(s2cell) → s2cell s2RangeMax(s2cell) → s2cell
The descendants of an S2 cell occupy a contiguous interval of the Hilbert curve, so an ancestor test is the pair of comparisons other >= s2RangeMin(cell) and other <= s2RangeMax(cell). That is what S2 brings that a hexagonal or a Web-Mercator grid does not, and it is a filter feeding the stbox index rather than an index key of its own.
SELECT s2RangeMin(s2cell '47c3c3'); -- 47c3c20000000001 SELECT s2RangeMax(s2cell '47c3c3'); -- 47c3c3ffffffffff
Return the descendant of an S2 cell at the given position along the Hilbert curve
s2CellToChild(s2cell,level integer,position integer) → s2cell
The level is exactly one finer than the cell's own, so the position runs from 0 to 3; cellToChildren, which the hierarchy section states, answers every descendant at any finer level.
SELECT s2CellToChild(s2cell '47c3c3', 11, 0); -- 47c3c24
Return the length in metres of an edge of an S2 cell
s2EdgeLength(s2cell,edge integer) → float
The edge runs from the vertex of the given index, which is 0 to 3, to the next one counterclockwise, and the length is measured on the WGS84 sphere.
SELECT round(s2EdgeLength(s2cell '47c3c3', 0)::numeric, 3); -- 9270.048
Return the four cells sharing an edge with an S2 cell
s2EdgeNeighbors(s2cell) → s2cellset
An S2 cell is a quadrilateral, so it has four edge neighbours and no ring of a given radius; the H3 grid disk has no S2 analogue.
SELECT s2EdgeNeighbors(s2cell '47c3c3');
-- {"47c3c1", "47c3c5", "47c3dd", "47c3e9"}
A region covering, which answers the set of cells approximating an arbitrary geometry, is the one S2 operation this chapter states no signature for: the S2 libraries publish it and MobilityDB does not yet carry a kernel for it.