Skip to main content
Version: 4.x

Region functions

These functions convert H3 indexes to and from polygonal areas.

polygonToCells

Each binding's version of polygonToCells takes as input a GeoJSON-like data structure describing a polygon (i.e., an outer ring and optional holes) and a target cell resolution. It produces a collection of cells that are contained within the polygon.

Containment is determined by centroids of the cells, so that a partitioning of polygons (covering an area without overlaps) will result in a partitioning of H3 cells.

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

In C, polygonToCells takes a GeoPolygon struct and preallocated, zeroed memory, and fills it with the covering cells.

Returns 0 (E_SUCCESS) on success.

maxPolygonToCellsSize

Provides an upper bound on the number of cells needed for memory allocation purposes when computing polygonToCells on the given GeoJSON-like data structure.

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

Returns 0 (E_SUCCESS) on success.

cellsToLinkedMultiPolygon / cellsToMultiPolygon

Create a GeoJSON-like multi-polygon describing the outline(s) of a set of cells. 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 expected that all cells 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.

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

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.

Returns 0 (E_SUCCESS) on success.

destroyLinkedMultiPolygon

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

void destroyLinkedMultiPolygon(LinkedGeoPolygon *polygon);