Skip to main content
Version: 4.x

Hierarchical grid functions

These functions permit moving between resolutions in the H3 grid system. The functions produce parent cells (coarser), or child cells (finer).

cellToParent

Provides the unique ancestor (coarser) cell of the given cell for the provided resolution. If the input cell has resolution r, then parentRes = r - 1 would give the immediate parent, parentRes = r - 2 would give the grandparent, and so on.

H3Error cellToParent(H3Index cell, int parentRes, H3Index *parent);

Returns 0 (E_SUCCESS) on success.

cellToChildren

Provides the children (descendant) cells of cell at resolution childRes.

H3Error cellToChildren(H3Index cell, int childRes, H3Index *children);

children must be an array of at least size cellToChildrenSize(cell, childRes).

Returns 0 (E_SUCCESS) on success.

cellToChildrenSize

Provides the number of children at a given resolution of the given cell.

H3Error cellToChildrenSize(H3Index cell, int childRes, int64_t *out);

Provides the size of the children array needed for the given inputs to cellToChildren.

Returns 0 (E_SUCCESS) on success.

cellToCenterChild

Provides the center child (finer) cell contained by cell at resolution childRes.

H3Error cellToCenterChild(H3Index cell, int childRes, H3Index *child);

Returns 0 (E_SUCCESS) on success.

cellToChildPos

Provides the position of the child cell within an ordered list of all children of the cell's parent at the specified resolution parentRes. The order of the ordered list is the same as that returned by cellToChildren. This is the complement of childPosToCell.

H3Error cellToChildPos(H3Index child, int parentRes, int64_t *out);

Returns 0 (E_SUCCESS) on success.

childPosToCell

Provides the child cell at a given position within an ordered list of all children of parent at the specified resolution childRes. The order of the ordered list is the same as that returned by cellToChildren. This is the complement of cellToChildPos.

H3Error childPosToCell(int64_t childPos, H3Index parent, int childRes, H3Index *child);

Returns 0 (E_SUCCESS) on success.

compactCells

Compacts a collection of H3 cells by recursively replacing children cells with their parents if all children are present. Input cells must all share the same resolution.

H3Error compactCells(const H3Index *cellSet, H3Index *compactedSet, const int64_t numCells);

Compacts cellSet into the array compactedSet. compactedSet must be at least the size of cellSet (in case the set cannot be compacted).

Returns 0 (E_SUCCESS) on success.

uncompactCells

Uncompacts the set compactedSet of indexes to the resolution res. h3Set must be at least of size uncompactCellsSize(compactedSet, numHexes, res).

H3Error uncompactCells(const H3Index *compactedSet, const int64_t numCells, H3Index *cellSet, const int64_t maxCells, const int res);

Returns 0 (E_SUCCESS) on success.

uncompactCellsSize

Provides the total resulting number of cells if uncompacting a cell set to a given resolution.

H3Error uncompactCellsSize(const H3Index *compactedSet, const int64_t numCompacted, const int res, int64_t *out);

Provides the size of the array needed by uncompactCells into out.

Returns 0 (E_SUCCESS) on success.