Skip to main content
Version: 4.x

Indexing functions

These functions are used for finding the H3 cell index containing coordinates, and for finding the center and boundary of H3 cells.

note

The C library works in radians: the lat and lng fields of LatLng (also used by CellBoundary, GeoLoop and GeoPolygon) are in radians. The bindings and the h3 command line tool take and return degrees. In C, use degsToRads and radsToDegs to convert.

latLngToCell​

Indexes the location at the specified resolution, providing the index of the cell containing the location. This buckets the geographic point into the H3 grid. For more information, see the algorithm description.

H3Error latLngToCell(const LatLng *g, int res, H3Index *out);

The latitude and longitude in g are in radians.

Returns 0 (E_SUCCESS) on success.

cellToLatLng​

Finds the center of the cell in grid space. See the algorithm description for more information.

The center will drift versus the centroid of the cell on Earth due to distortion from the gnomonic projection within the icosahedron face it resides on and its distance from the center of the icosahedron face.

H3Error cellToLatLng(H3Index cell, LatLng *g);

The latitude and longitude written to g are in radians.

Returns 0 (E_SUCCESS) on success.

cellToBoundary​

Finds the boundary of the cell. For more information, see the algorithm description.

H3Error cellToBoundary(H3Index cell, CellBoundary *bndry);

The vertices written to bndry are in radians.

Returns 0 (E_SUCCESS) on success.