An H3 cell is a hexagon on an icosahedron, so it has neighbours through six edges, vertices shared with them, and a base cell among the 122 the icosahedron carries. Twelve cells at each resolution are pentagons. None of that has a counterpart in a square or a spherical quadrilateral grid.
Return the temporal base-cell number (0–121) of each cell in a trajectory
th3GetBaseCellNumber(th3index) → tint
SELECT th3GetBaseCellNumber(th3index '831c02fffffffff@2001-01-01'); -- 14@2001-01-01
Return a temporal boolean stating whether each cell has Class-III orientation
th3IsResClassIii(th3index) → tbool
Class III alternates with resolution: odd resolutions are class III, even are class II.
SELECT th3IsResClassIii(th3index '871fa44a8ffffff@2001-01-01'); -- t@2001-01-01
Return a temporal boolean stating whether each cell is a pentagon
th3IsPentagon(th3index) → tbool
12 cells per resolution are pentagons, the remaining 110 at each base cell descend as hexagons.
SELECT th3IsPentagon(th3index '831c00fffffffff@2001-01-01'); -- t@2001-01-01 SELECT th3IsPentagon(th3index '831c02fffffffff@2001-01-01'); -- f@2001-01-01
Return the temporal center-child cell at the given resolution
th3CellToCenterChild(th3index,integer) → th3index th3CellToCenterChild(th3index) → th3index
The no-argument form drops to the next-finer resolution.
SELECT th3CellToCenterChild(th3index '871fa44a8ffffff@2001-01-01', 8); -- 881fa44a81fffff@2001-01-01 SELECT th3CellToCenterChild(th3index '871fa44a8ffffff@2001-01-01'); -- 881fa44a81fffff@2001-01-01
Return the ordinal position (0-based) of each cell among the children of its parent at the given resolution
th3CellToChildPos(th3index,integer) → tbigint
SELECT th3CellToChildPos(th3index '871fa44a8ffffff@2001-01-01', 6); -- 0@2001-01-01
Return the temporal child cell at a given ordinal position of the given parent, at the given child resolution
th3ChildPosToCell(tbigint,th3index,integer) → th3index
SELECT th3ChildPosToCell(tbigint '0@2001-01-01', th3index '871fa44a8ffffff@2001-01-01', 8); -- 881fa44a81fffff@2001-01-01
The cells at exactly k grid steps from the origin
h3GridRing(h3index,integer) → h3indexset
Fails near pentagons.
SELECT h3GridRing(h3index '871fa44a8ffffff', 1);
/* {"871fa44a9ffffff", "871fa44aaffffff", "871fa44abffffff", "871fa44acffffff",
"871fa44adffffff", "871fa44aeffffff"} */
The inclusive path of cells between two cells of the same resolution
h3GridPathCells(h3index,h3index) → h3indexset
SELECT h3GridPathCells(h3index '871fa44a8ffffff', h3index '871fa44b1ffffff');
/* {"871fa4484ffffff", "871fa44a3ffffff", "871fa44a8ffffff", "871fa44aeffffff",
"871fa44b1ffffff"} */
All outgoing directed edges of a cell
h3OriginToDirectedEdges(h3index) → h3indexset
6 for a hexagon and 5 for a pentagon.
SELECT h3OriginToDirectedEdges(h3index '871fa44a8ffffff');
/* {"1171fa44a8ffffff", "1271fa44a8ffffff", "1371fa44a8ffffff", "1471fa44a8ffffff",
"1571fa44a8ffffff", "1671fa44a8ffffff"} */
All vertexes of a cell
h3CellToVertexes(h3index) → h3indexset
6 for a hexagon and 5 for a pentagon.
SELECT h3CellToVertexes(h3index '871fa44a8ffffff');
/* {"2071fa44a8ffffff", "2171fa44a8ffffff", "2271fa44a8ffffff", "2371fa44a8ffffff",
"2471fa44a8ffffff", "2571fa44a8ffffff"} */
The icosahedron face indexes (0..19) intersected by a cell
h3GetIcosahedronFaces(h3index) → intset
SELECT h3GetIcosahedronFaces(h3index '831c02fffffffff');
-- {6, 11}
Return the temporal length of each directed edge in a trajectory, in metres
th3EdgeLength(th3index) → tfloat
SELECT th3EdgeLength(th3CellsToDirectedEdge(th3index '871fa44a8ffffff@2001-01-01',
th3index '871fa44aeffffff@2001-01-01'));
-- 1.272084901305088@2001-01-01
Return the temporal great-circle distance between two temporal geodetic points (not between cells)
greatCircleDistance(tgeogpoint,tgeogpoint) → tfloat
SELECT greatCircleDistance(tgeogpoint 'Point(0 0)@2001-01-01', tgeogpoint 'Point(1 0)@2001-01-01'); -- 111.19505197522943@2001-01-01
Return a temporal boolean stating whether two temporal cells are grid neighbours at each instant
th3AreNeighborCells(th3index,th3index) → tbool
SELECT th3AreNeighborCells(th3index '880326b885fffff@2001-01-01', th3index '880326b88dfffff@2001-01-01'); -- t@2001-01-01
Return a temporal directed-edge identifier from an origin/destination pair of temporal cells
th3CellsToDirectedEdge(th3index,th3index) → th3index
SELECT th3CellsToDirectedEdge(th3index '871fa44a8ffffff@2001-01-01',
th3index '871fa44aeffffff@2001-01-01');
-- 1671fa44a8ffffff@2001-01-01
Return a temporal boolean stating at each instant whether the value is a valid H3 directed edge
isValidDirectedEdge(tcell) → tbool
H3 directed edges are themselves 64-bit identifiers (encoded differently from cell identifiers, isValidDirectedEdge distinguishes them). The MobilityDB th3index type carries directed edges by convention: the same type, interpreted through edge-specific accessors.
SELECT isValidDirectedEdge(th3CellsToDirectedEdge(th3index '871fa44a8ffffff@2001-01-01',
th3index '871fa44aeffffff@2001-01-01'));
-- t@2001-01-01
SELECT isValidDirectedEdge(th3index '871fa44a8ffffff@2001-01-01');
-- f@2001-01-01
Return the temporal origin or destination cell of a temporal directed edge
th3GetDirectedEdgeOrigin(th3index) → th3index th3GetDirectedEdgeDestination(th3index) → th3index
SELECT th3GetDirectedEdgeOrigin(th3CellsToDirectedEdge(th3index '871fa44a8ffffff@2001-01-01', th3index '871fa44aeffffff@2001-01-01')); -- 871fa44a8ffffff@2001-01-01 SELECT th3GetDirectedEdgeDestination(th3CellsToDirectedEdge(th3index '871fa44a8ffffff@2001-01-01', th3index '871fa44aeffffff@2001-01-01')); -- 871fa44aeffffff@2001-01-01
Return the temporal polygon boundary of each directed edge in a trajectory, as a temporal geography
th3DirectedEdgeToBoundary(th3index) → tgeography
SELECT ST_NPoints(getValue(th3DirectedEdgeToBoundary(
th3CellsToDirectedEdge(th3index '871fa44a8ffffff@2001-01-01',
th3index '871fa44aeffffff@2001-01-01')))::geometry);
-- 3
Return the temporal H3 vertex at the given vertex number
th3CellToVertex(th3index,integer) → th3index
0–5 for hexagons, 0–4 for pentagons.
SELECT th3CellToVertex(th3index '871fa44a8ffffff@2001-01-01', 0); -- 2071fa44a8ffffff@2001-01-01
Return the temporal geodetic coordinates of each vertex in a trajectory
th3VertexToPoint(th3index) → tgeogpoint
SELECT asText(th3VertexToPoint(th3CellToVertex(th3index '871fa44a8ffffff@2001-01-01', 0)), 6); -- POINT(4.280027 50.807655)@2001-01-01
Return a temporal boolean stating at each instant whether the value is a valid H3 vertex
isValidVertex(tcell) → tbool
SELECT isValidVertex(th3CellToVertex(th3index '871fa44a8ffffff@2001-01-01', 0)); -- t@2001-01-01
Return the temporal grid-hop distance (number of single-cell steps) between two temporal cells
th3GridDistance(th3index,th3index) → tbigint tcell <-> tcell → tbigint
Equivalently, the <-> operator returns the same distance.
SELECT th3index '880326b885fffff@2001-01-01' <-> th3index '880326b88dfffff@2001-01-01'; -- 1@2001-01-01
Convert between a temporal cell and a temporal local (I, J) coordinate pair relative to an origin temporal cell
th3CellToLocalIj(th3index,th3index) → tgeompoint th3LocalIjToCell(th3index,tgeompoint) → th3index
The local coordinate is exposed as a tgeompoint with the I axis in the x slot and J in y.
SELECT asText(th3CellToLocalIj(th3index '871fa44a8ffffff@2001-01-01',
th3index '871fa44aeffffff@2001-01-01'));
-- POINT(497 320)@2001-01-01
SELECT th3LocalIjToCell(th3index '871fa44a8ffffff@2001-01-01',
th3CellToLocalIj(th3index '871fa44a8ffffff@2001-01-01',
th3index '871fa44aeffffff@2001-01-01'));
-- 871fa44aeffffff@2001-01-01