Awesome Go

H3

CategoryGeographic
SubcategoryGeographic
Stars461

Go bindings for H3, a hierarchical hexagonal geospatial indexing system

About H3

Build Nightly Coverage Status License Go Reference H3 Version

H3-Go

This library is a pure-Go implementation of the H3 Core Library. It needs no C toolchain and no cgo. 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

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, err := h3.LatLngToCell(latLng, resolution)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(cell)
	// Output:
	// 8928308280fffff
}

C API

Notes

  • LatLng returns Lat and Lng as degrees, instead of radians.
  • H3 C API function prefixes of get have been dropped in support of Golang's Getter naming style.
  • Convenience methods have been added to various types where that type was the main or only argument.

Bindings

C APIGo API
latLngToCellLatLngToCell, LatLng#Cell
cellToLatLngCellToLatLng, Cell#LatLng
cellToBoundaryCellToBoundary, Cell#Boundary
gridDiskGridDisk, Cell#GridDisk
gridDisksUnsafeGridDisksUnsafe
gridDiskDistancesGridDiskDistances, Cell#GridDiskDistances
gridDiskDistancesSafeGridDiskDistancesSafe, Cell#GridDiskDistancesSafe
gridDiskDistancesUnsafeGridDiskDistancesUnsafe, Cell#GridDiskDistancesUnsafe
gridRingGridRing, Cell#GridRing
gridRingUnsafeGridRingUnsafe, Cell#GridRingUnsafe
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
cellToChildrenSizeCell#ChildrenSize
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
edgeToVertexesDirectedEdge#Vertexes
cellToVertexCellToVertex
cellToVertexesCellToVertexes
vertexToLatLngVertexToLatLng
isValidVertexIsValidVertex
gridDistanceGridDistance, Cell#GridDistance
gridPathCellsGridPath, Cell#GridPath
cellToLocalIjCellToLocalIJ
localIjToCellLocalIJToCell

Conformance

Since v4.6 the package is pure Go; earlier v4 releases were a cgo binding to the C library. Its outputs are held to the H3 reference by the conformance suite in conformance/, whose README states the contract: discrete outputs (indexes, counts, booleans, errors, sets and sequences of indexes) are identical to the reference; coordinates agree within 1e-12 degrees of arc and measures within 1e-9 relative; knife-edge inputs, such as points on cell edges and polygon vertices on cell edges, are outside the contract. The suite's README also lists where this implementation deliberately differs from the reference.

The reference sources the suite is generated from are pinned as a git submodule at third_party/h3. They are needed only to regenerate the suite (git submodule update --init third_party/h3, then go generate ./conformance), never to build or test the package.

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.

Frequently Asked Questions

What is H3?

H3 is a Geographic library for the Go programming language. Go bindings for H3, a hierarchical hexagonal geospatial indexing system

How do I install H3?

Install H3 with the Go module system using `go get uber/h3-go`. Check the repository for the current installation instructions.

What category does H3 belong to?

H3 is listed under Geographic, specifically Geographic.

← Back to Geographic