Skip to main content
Version: 4.x

Miscellaneous H3 functions

These functions include descriptions of the H3 grid system.

degsToRads​

Converts degrees to radians.

double degsToRads(double degrees);

radsToDegs​

Converts radians to degrees.

double radsToDegs(double radians);

getHexagonAreaAvgKm2​

Average hexagon area in square kilometers at the given resolution. Excludes pentagons.

H3Error getHexagonAreaAvgKm2(int res, double *out);

getHexagonAreaAvgM2​

Average hexagon area in square meters at the given resolution. Excludes pentagons.

H3Error getHexagonAreaAvgM2(int res, double *out);

cellAreaRads2​

Exact area of specific cell in square radians.

H3Error cellAreaRads2(H3Index h, double *out);

cellAreaKm2​

Exact area of specific cell in square kilometers.

H3Error cellAreaKm2(H3Index h, double *out);

cellAreaM2​

Exact area of specific cell in square meters.

H3Error cellAreaM2(H3Index h, double *out);

getHexagonEdgeLengthAvgKm​

Average hexagon edge length in kilometers at the given resolution. Excludes pentagons.

H3Error getHexagonEdgeLengthAvgKm(int res, double *out);

getHexagonEdgeLengthAvgM​

Average hexagon edge length in meters at the given resolution. Excludes pentagons.

H3Error getHexagonEdgeLengthAvgM(int res, double *out);

edgeLengthKm​

Exact edge length of specific unidirectional edge in kilometers.

H3Error edgeLengthKm(H3Index edge, double *length);

edgeLengthM​

Exact edge length of specific unidirectional edge in meters.

H3Error edgeLengthM(H3Index edge, double *length);

edgeLengthRads​

Exact edge length of specific unidirectional edge in radians.

H3Error edgeLengthRads(H3Index edge, double *length);

getNumCells​

Number of unique H3 indexes at the given resolution.

H3Error getNumCells(int res, int64_t *out);

getRes0Cells​

Provide all the resolution 0 H3 cells. These are the coarsest cells that can be represented in the H3 system and are the parents/ancestors of all other cells in the H3 grid system. The returned cells correspond to the 122 base cells.

H3Error getRes0Cells(H3Index *out);

out must be an array of at least size res0CellCount().

res0CellCount​

Number of resolution 0 H3 indexes, which is defined as 122.

int res0CellCount(void);

getPentagons​

All the pentagon H3 cells at the specified resolution. There are 12 pentagons at each resolution.

H3Error getPentagons(int res, H3Index *out);

out must be an array of at least size pentagonIndexCount().

Returns 0 (E_SUCCESS) on success.

pentagonCount​

Number of pentagon H3 cells per resolution. This is always 12, but provided as a convenience.

int pentagonCount(void);

greatCircleDistanceKm​

Gives the "great circle" or "haversine" distance between pairs of LatLng points (lat/lng pairs) in kilometers.

double greatCircleDistanceKm(const LatLng *a, const LatLng *b);

greatCircleDistanceM​

Gives the "great circle" or "haversine" distance between pairs of LatLng points (lat/lng pairs) in meters.

double greatCircleDistanceM(const LatLng *a, const LatLng *b);

greatCircleDistanceRads​

Gives the "great circle" or "haversine" distance between pairs of LatLng points (lat/lng pairs) in radians.

double greatCircleDistanceRads(const LatLng *a, const LatLng *b);

describeH3Error​

Provides a human-readable description of an H3Error error code.

char *describeH3Error(H3Error err);

This function cannot fail, as it just returns a string stating that the H3Error value is itself invalid and does not allocate memory to do so. Do not call free on the result of this function.