Home

Awesome

<img align="right" src="https://uber.github.io/img/h3Logo-color.svg" alt="H3 Logo" width="200">

Build Coverage Status Go Report Card License GoDoc H3 Version

<h1 align="center">H3-Go is looking for a maintainer familiar with Go, C, and H3. Volunteers welcome! Please get in touch with us on the <a href="https://join.slack.com/t/h3-core/shared_invite/zt-g6u5r1hf-W_~uVJmfeiWtMQuBGc1NNg">H3 Slack</a>.</h1>

H3-Go

This library provides Golang bindings for the H3 Core Library. For API reference, see the H3 Documentation.

This is v4 of this library, supporting H3 v4.

Check out v3 or checkout the git tag for the version you need.

Migrating from v3?

Check out v3 to v4 migration guide. There have been no breaking changes to the format of H3 indexes. Indexes generated by older versions can be parsed in v4, and vice-versa.

Usage

Prerequisites

H3-Go requires CGO (CGO_ENABLED=1) in order to be built. Go should do the right thing when including this library:

The cgo tool is enabled by default for native builds on systems where it is expected to work. It is disabled by default when cross-compiling. You can control this by setting the CGO_ENABLED environment variable when running the go tool: set it to 1 to enable the use of cgo, and to 0 to disable it. The go tool will set the build constraint "cgo" if cgo is enabled. The special import "C" implies the "cgo" build constraint, as though the file also said "// +build cgo". Therefore, if cgo is disabled, files that import "C" will not be built by the go tool. (For more about build constraints see https://golang.org/pkg/go/build/#hdr-Build_Constraints).

If you see errors/warnings like "build constraints exclude all Go files...", then the cgo build constraint is likely disabled; try setting CGO_ENABLED=1 environment variable in your go build step.

Installation

go get github.com/uber/h3-go/v4

Quickstart

import "github.com/uber/h3-go/v4"

func ExampleLatLngToCell() {
 latLng := h3.NewLatLng(37.775938728915946, -122.41795063018799)
 resolution := 9 // between 0 (biggest cell) and 15 (smallest cell)

 cell := h3.LatLngToCell(latLng, resolution)

 fmt.Printf("%s", cell)
 // Output:
 // 8928308280fffff
}

C API

Notes

Bindings

C APIGo API
latLngToCellLatLngToCell, LatLng#Cell
cellToLatLngCellToLatLng, Cell#LatLng
cellToBoundaryCellToBoundary, Cell#Boundary
gridDiskGridDisk, Cell#GridDisk
gridDiskDistancesGridDiskDistances, Cell#GridDiskDistances
gridRingUnsafeN/A
polygonToCellsPolygonToCells, GeoPolygon#Cells
cellsToMultiPolygonCellsToMultiPolygon
degsToRadsDegsToRads
radsToDegsRadsToDegs
greatCircleDistanceGreatCircleDistance* (3/3)
getHexagonAreaAvgHexagonAreaAvg* (3/3)
cellAreaCellArea* (3/3)
getHexagonEdgeLengthAvgHexagonEdgeLengthAvg* (2/2)
exactEdgeLengthEdgeLength* (3/3)
getNumCellsNumCells
getRes0CellsRes0Cells
getPentagonsPentagons
getResolutionResolution
getBaseCellNumberBaseCellNumber, Cell#BaseCellNumber
stringToH3IndexFromString, Cell#UnmarshalText
h3ToStringIndexToString, Cell#String, Cell#MarshalText
isValidCellCell#IsValid
cellToParentCell#Parent, Cell#ImmediateParent
cellToChildrenCell#Children Cell#ImmediateChildren
cellToCenterChildCell#CenterChild
compactCellsCompactCells
uncompactCellsUncompactCells
isResClassIIICell#IsResClassIII
isPentagonCell#IsPentagon
getIcosahedronFacesCell#IcosahedronFaces
areNeighborCellsCell#IsNeighbor
cellsToDirectedEdgeCell#DirectedEdge
isValidDirectedEdgeDirectedEdge#IsValid
getDirectedEdgeOriginDirectedEdge#Origin
getDirectedEdgeDestinationDirectedEdge#Destination
directedEdgeToCellsDirectedEdge#Cells
originToDirectedEdgesCell#DirectedEdges
directedEdgeToBoundaryDirectedEdge#Boundary
cellToVertexCellToVertex
cellToVertexesCellToVertexes
vertexToLatLngVertexToLatLng
isValidVertexIsValidVertex
gridDistanceGridDistance, Cell#GridDistance
gridPathCellsGridPath, Cell#GridPath
cellToLocalIjCellToLocalIJ
localIjToCellLocalIJToCell

CGO

The H3 C source code and header files are copied into this project to optimize for portability. h3-go can be imported into any Go project for any platform that CGO supports.

Contributing

Pull requests and Github issues are welcome. Please read our contributing guide for more information.

Legal and Licensing

H3-Go is licensed under the Apache 2.0 License.