Skip to main content
Version: 4.x

Region functions

These functions convert H3 indexes to and from polygonal areas.

polygonToCells

H3Error polygonToCells(const GeoPolygon *geoPolygon, int res, uint32_t flags, H3Index *out);

polygonToCells takes a given GeoJSON-like data structure and preallocated, zeroed memory, and fills it with the hexagons that are contained by the GeoJSON-like data structure.

Containment is determined by the cells' centroids. A partitioning using the GeoJSON-like data structure, where polygons cover an area without overlap, will result in a partitioning in the H3 grid, where cells cover the same area without overlap.

Returns 0 (E_SUCCESS) on success.

maxPolygonToCellsSize

H3Error maxPolygonToCellsSize(const GeoPolygon *geoPolygon, int res, uint32_t flags, int64_t *out);

maxPolygonToCellsSize returns the number of hexagons to allocate space for when computing polygonToCells on the given GeoJSON-like data structure.

Returns 0 (E_SUCCESS) on success.

cellsToLinkedMultiPolygon / cellsToMultiPolygon

H3Error cellsToLinkedMultiPolygon(const H3Index *h3Set, const int numHexes, LinkedGeoPolygon *out);

Create a LinkedGeoPolygon describing the outline(s) of a set of hexagons. Polygon outlines will follow GeoJSON MultiPolygon order: Each polygon will have one outer loop, which is first in the list, followed by any holes.

It is the responsibility of the caller to call destroyLinkedPolygon on the populated linked geo structure, or the memory for that structure will not be freed.

It is expected that all hexagons in the set have the same resolution and that the set contains no duplicates. Behavior is undefined if duplicates or multiple resolutions are present, and the algorithm may produce unexpected or invalid output.

Returns 0 (E_SUCCESS) on success.

destroyLinkedMultiPolygon

void destroyLinkedMultiPolygon(LinkedGeoPolygon *polygon);

Free all allocated memory for a linked geo structure. The caller is responsible for freeing memory allocated to the input polygon struct.