Skip to main content
Version: 4.x

Index inspection functions

These functions provide metadata about an H3 index, such as its resolution or base cell, and provide utilities for converting into and out of the 64-bit representation of an H3 index.

getResolution

Returns the resolution of the index. (Works for cells, edges, and vertexes.)

int getResolution(H3Index h);

getBaseCellNumber

Returns the base cell number of the index. (Works for cells, edges, and vertexes.)

int getBaseCellNumber(H3Index h);

getIndexDigit

Returns an indexing digit of the index. Works for cells, edges and vertexes.

H3Error getIndexDigit(H3Index h, int res, H3Index *out);

Digits are 1-indexed starting with the resolution 1 digit.

This function will return unused index digits as well as used ones, in that case they will be 7 for valid cells.

constructCell

Creates a cell from its components (resolution, base cell number, and indexing digits). This is the inverse operation of getResolution, getBaseCellNumber, and getIndexDigit. Only allows for constructing valid H3 cells, and will return an error if the provided components would create an invalid cell.

H3Error constructCell(int res, int baseCellNumber, const int *digits, H3Index *out);
  • res: Resolution (0-15)
  • baseCellNumber: Base cell number (0-121)
  • digits: Array of indexing digits (0-6) of length res. Each digit digits[i] corresponds to the digit at resolution i+1. Can be NULL if res is 0.
  • out: Output parameter for the constructed cell

Returns 0 (E_SUCCESS) on success. Returns an error code on failure:

  • E_RES_DOMAIN: Invalid resolution (must be 0-15)
  • E_BASE_CELL_DOMAIN: Invalid base cell number (must be 0-121)
  • E_DIGIT_DOMAIN: Invalid digit value (must be 0-6)
  • E_DELETED_DIGIT: Attempted to use digit 1 in a pentagon base cell (deleted subsequence)
note

When constructing a cell from a pentagon base cell, digit 1 (K_AXES_DIGIT) is not allowed to follow immediately after a sequence of 0 digits. In this case, the function will return E_DELETED_DIGIT.

stringToH3

Converts the string representation to H3Index (uint64_t) representation.

H3Error stringToH3(const char *str, H3Index *out);

Returns 0 (E_SUCCESS) on success.

h3ToString

Converts the H3Index representation of the index to the string representation.

H3Error h3ToString(H3Index h, char *str, size_t sz);

str must be at least of length 17. Returns 0 (E_SUCCESS) on success.

isValidCell

Returns non-zero if this is a valid H3 cell index.

int isValidCell(H3Index h);

isValidIndex

Returns non-zero if this is a valid H3 index for any mode (cell, directed edge, or vertex). That is, this returns true if any of the functions isValidCell, isValidDirectedEdge, or isValidVertex would return true.

int isValidIndex(H3Index h);

Returns 1 if the H3 index is valid for any supported type (cell, directed edge, or vertex), 0 otherwise.

isResClassIII

Returns non-zero if this index has a resolution with Class III orientation.

int isResClassIII(H3Index h);

isPentagon

Returns non-zero if this index represents a pentagonal cell.

int isPentagon(H3Index h);

getIcosahedronFaces

Find all icosahedron faces intersected by a given H3 cell. Faces are represented as integers from 0-19, inclusive.

H3Error getIcosahedronFaces(H3Index h, int* out);

Face values are placed in the array out. out must be at least length of maxFaceCount(h). The array is sparse, and empty (no intersection) array values are represented by -1.

Returns 0 (E_SUCCESS) on success.

maxFaceCount

Returns the maximum number of icosahedron faces the given H3 index may intersect.

H3Error maxFaceCount(H3Index h3, int *out);

Returns 0 (E_SUCCESS) on success.