H3Geo (H3Geo v0.1.1)

H3Geo implements the H3 geospatial indexing system.

It's a wrapper around the h3o Rust library, using Rustler to expose functions from the library in a manner that can be easily called from Elixir.

Currently only a handful of functions are implemented, mostly to do with converting existing geometries into H3 cell indexes.

Summary

Functions

Takes a list of indexes and returns the compact indexes.

Takes Geo.MultiPolygon and an integer precision and returns a list of integers representing the H3 cells that intersect with the multipolygon.

Takes a Geo.Point and an integer precision and returns an integer representing the H3 Cell.

Takes Geo.Polygon and an integer precision and returns a list of integers representing the H3 cells that intersect with the polygon.

Takes a list of indexes and returns the uncompacted indexes at the desired precision.

Types

@type index() :: pos_integer()
@type precision() :: 0..15

Functions

Link to this function

compact(indexes)

@spec compact([index()]) ::
  {:ok, [index()]} | {:error, :invalid_cell_index | :compaction_error}

Takes a list of indexes and returns the compact indexes.

The incoming list is filtered for unique values automatically.

Rust documentation

Link to this function

multipolygon_to_cells(multipolygon, precision)

@spec multipolygon_to_cells(Geo.MultiPolygon.t(), precision()) ::
  {:ok, [index()]} | {:error, :invalid_resolution | :invalid_geometry}

Takes Geo.MultiPolygon and an integer precision and returns a list of integers representing the H3 cells that intersect with the multipolygon.

Uses the Covers containment mode, so the cells returned fully cover the multipolygon.

Rust documentation

Link to this function

point_to_cell(point, precision)

@spec point_to_cell(Geo.Point.t(), precision()) ::
  {:ok, pos_integer()} | {:error, :invalid_lat_lng | :invalid_resolution}

Takes a Geo.Point and an integer precision and returns an integer representing the H3 Cell.

Rust documentation.

Link to this function

polygon_to_cells(polygon, precision)

@spec polygon_to_cells(Geo.Polygon.t(), precision()) ::
  {:ok, [index()]} | {:error, :invalid_resolution | :invalid_geometry}

Takes Geo.Polygon and an integer precision and returns a list of integers representing the H3 cells that intersect with the polygon.

Uses the Covers containment mode, so the cells returned fully cover the polygon.

Rust documentation

Link to this function

uncompact(indexes, resolution)

@spec uncompact([index()], precision()) ::
  {:ok, [index()]} | {:error, :invalid_cell_index | :invalid_resolution}

Takes a list of indexes and returns the uncompacted indexes at the desired precision.

Rust documentation