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.)
- C
- Java
- JavaScript (Live)
- Python
- Go
- DuckDB
- Shell
int getResolution(H3Index h);
int getResolution(long h3);
int getResolution(String h3Address);
h3.getResolution(h)
h3.get_resolution(h)
cell.Resolution()
h3_get_resolution(h)
$ h3 getResolution --help
h3: Extracts the resolution (0 - 15) from the H3 cell
H3 4.1.0
getResolution Extracts the resolution (0 - 15) from the H3 cell
-h, --help Show this help message.
-c, --cell <index> Required. H3 Cell
$ h3 getResolution -c 85283473fffffff
5
getBaseCellNumber
Returns the base cell number of the index. (Works for cells, edges, and vertexes.)
- C
- Java
- JavaScript (Live)
- Python
- Go
- DuckDB
- Shell
int getBaseCellNumber(H3Index h);
int getBaseCellNumber(long h3);
int getBaseCellNumber(String h3Address);
h3.getBaseCellNumber(h)
h3.get_base_cell_number(h)
cell.BaseCellNumber()
h3_get_base_cell_number(h)
$ h3 getBaseCellNumber --help
h3: Extracts the base cell number (0 - 121) from the H3 cell
H3 4.1.0
getBaseCellNumber Extracts the base cell number (0 - 121) from the H3 cell
-h, --help Show this help message.
-c, --cell <index> Required. H3 Cell
$ h3 getBaseCellNumber -c 85283473fffffff
20
getIndexDigit
Returns an indexing digit of the index. Works for cells, edges and vertexes.
- C
- Shell
H3Error getIndexDigit(H3Index h, int res, H3Index *out);
int getIndexDigit(long h3, int res);
int getIndexDigit(String h3Address, int res);
h3.getIndexDigit(h, res)
h3.get_index_digit(h, res)
cell.IndexDigit(res)
h3_get_index_digit(h, res)
$ h3 getIndexDigit --help
h3: Extracts the indexing digit (0 - 7) from the H3 cell
H3 4.3.0
getIndexDigit Extracts the indexing digit (0 - 7) from the H3 cell
-h, --help Show this help message.
-c, --cell <index> Required. H3 Cell
-r, --res <res> Required. Indexing resolution (1 - 15)
$ h3 getIndexDigit -c 85283473fffffff -r 2
7
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.
- C
- Java
- JavaScript (Live)
- Python
- Go
- DuckDB
- Shell
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 lengthres. Each digitdigits[i]corresponds to the digit at resolutioni+1. Can beNULLifresis 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)
This function may not be available in all bindings.
This function may not be available in all bindings.
This function may not be available in all bindings.
This function may not be available in all bindings.
This function may not be available in all bindings.
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.
- C
- Java
- JavaScript (Live)
- Python
- Go
- DuckDB
- Shell
H3Error stringToH3(const char *str, H3Index *out);
Returns 0 (E_SUCCESS) on success.
long stringToH3(String h3Address);
The H3 JavaScript binding supports only the string representation of an H3 index.
h3.str_to_int(h)
h3.IndexFromString(str)
h3_string_to_h3(h)
The H3 CLI supports only the string representation of an H3 index.
h3ToString
Converts the H3Index representation of the index to the string representation.
- C
- Java
- JavaScript (Live)
- Python
- Go
- DuckDB
- Shell
H3Error h3ToString(H3Index h, char *str, size_t sz);
str must be at least of length 17.
Returns 0 (E_SUCCESS) on success.
String h3ToString(long h3);
The H3 JavaScript binding supports only the string representation of an H3 index.
h3.int_to_str(h)
cell.String()
h3_h3_to_string(h)
The H3 CLI supports only the string representation of an H3 index.
isValidCell
Returns non-zero if this is a valid H3 cell index.
- C
- Java
- JavaScript (Live)
- Python
- Go
- DuckDB
- Shell
int isValidCell(H3Index h);
boolean isValidCell(long h3);
boolean isValidCell(String h3Address);
h3.isValidCell(h)
h3.is_valid_cell(h)
cell.IsValid()
h3_is_valid_cell(h)
$ h3 isValidCell --help
h3: Checks if the provided H3 index is actually valid
H3 4.1.0
isValidCell Checks if the provided H3 index is actually valid
-h, --help Show this help message.
-c, --cell <index> Required. H3 Cell
-f, --format <FMT> 'json' for true or false, 'numeric' for 1 or 0 (Default: json)
$ h3 isValidCell -c 85283473fffffff
true
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.
- C
- Java
- JavaScript (Live)
- Python
- Go
- DuckDB
- Shell
int isValidIndex(H3Index h);
Returns 1 if the H3 index is valid for any supported type (cell, directed edge, or vertex), 0 otherwise.
This function may not be available in all bindings.
This function may not be available in all bindings.
This function may not be available in all bindings.
This function may not be available in all bindings.
This function may not be available in all bindings.
isResClassIII
Returns non-zero if this index has a resolution with Class III orientation.
- C
- Java
- JavaScript (Live)
- Python
- Go
- DuckDB
- Shell
int isResClassIII(H3Index h);
boolean isResClassIII(long h3);
boolean isResClassIII(String h3Address);
h3.isResClassIII(h)
h3.is_res_class_III(h)
cell.IsResClassIII()
h3_is_res_class_iii(h)
$ h3 isResClassIII --help
h3: Checks if the provided H3 index has a Class III orientation
H3 4.1.0
isResClassIII Checks if the provided H3 index has a Class III orientation
-h, --help Show this help message.
-c, --cell <index> Required. H3 Cell
-f, --format <FMT> 'json' for true or false, 'numeric' for 1 or 0 (Default: json)
$ h3 isResClassIII -c 85283473fffffff
true
isPentagon
Returns non-zero if this index represents a pentagonal cell.
- C
- Java
- JavaScript (Live)
- Python
- Go
- DuckDB
- Shell
int isPentagon(H3Index h);
boolean isPentagon(long h3);
boolean isPentagon(String h3Address);
h3.isPentagon(h)
h3.is_pentagon(h)
cell.IsPentagon()
h3_is_pentagon(h)
$ h3 isPentagon --help
h3: Checks if the provided H3 index is a pentagon instead of a hexagon
H3 4.1.0
isPentagon Checks if the provided H3 index is a pentagon instead of a hexagon
-h, --help Show this help message.
-c, --cell <index> Required. H3 Cell
-f, --format <FMT> 'json' for true or false, 'numeric' for 1 or 0 (Default: json)
$ h3 isPentagon -c 85283473fffffff
false
getIcosahedronFaces
Find all icosahedron faces intersected by a given H3 cell. Faces are represented as integers from 0-19, inclusive.
- C
- Java
- JavaScript (Live)
- Python
- Go
- DuckDB
- Shell
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.
Collection<Integer> getIcosahedronFaces(long h3);
Collection<Integer> getIcosahedronFaces(String h3Address);
h3.getIcosahedronFaces(h)
h3.get_icosahedron_faces(h)
cell.IcosahedronFaces()
h3_get_icosahedron_faces(h)
$ h3 getIcosahedronFaces --help
h3: Returns the icosahedron face numbers (0 - 19) that the H3 index intersects
H3 4.1.0
getIcosahedronFaces Returns the icosahedron face numbers (0 - 19) that the H3 index intersects
-h, --help Show this help message.
-c, --cell <index> Required. H3 Cell
-f, --format <FMT> 'json' for [faceNum, ...], 'newline' for faceNum\n... (Default: json)
$ h3 getIcosahedronFaces -c 85283473fffffff
[7]
maxFaceCount
Returns the maximum number of icosahedron faces the given H3 index may intersect.
- C
- Java
- JavaScript (Live)
- Python
- Go
- DuckDB
- Shell
H3Error maxFaceCount(H3Index h3, int *out);
Returns 0 (E_SUCCESS) on success.
This function exists for memory management and is not exposed.
This function exists for memory management and is not exposed.
This function exists for memory management and is not exposed.
This function exists for memory management and is not exposed.
This function exists for memory management and is not exposed.
This function exists for memory management and is not exposed.