h3

package module
v3.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2021 License: Apache-2.0 Imports: 5 Imported by: 18

Documentation

Overview

Package h3 is the go binding for Uber's H3 Geo Index system. It uses cgo to link with a statically compiled h3 library

Index

Examples

Constants

View Source
const (
	// MaxCellBndryVerts is the maximum number of vertices that can be used
	// to represent the shape of a cell.
	MaxCellBndryVerts = C.MAX_CELL_BNDRY_VERTS

	// MaxResolution is the maximum H3 resolution a GeoCoord can be indexed to.
	MaxResolution = C.MAX_H3_RES

	// The number of faces on an icosahedron
	NumIcosaFaces = C.NUM_ICOSA_FACES

	// The number of H3 base cells
	NumBaseCells = C.NUM_BASE_CELLS

	// InvalidH3Index is a sentinel value for an invalid H3 index.
	InvalidH3Index = C.H3_NULL
)

Variables

View Source
var (
	// ErrPentagonEncountered is returned by functions that encounter a pentagon
	// and cannot handle it.
	ErrPentagonEncountered = errors.New("pentagon encountered")

	// ErrInvalidResolution is returned when the requested resolution is not valid
	ErrInvalidResolution = errors.New("resolution invalid")
)

Functions

func AreNeighbors

func AreNeighbors(h1, h2 H3Index) bool

AreNeighbors returns true if `h1` and `h2` are neighbors. Two indexes are neighbors if they share an edge.

func BaseCell

func BaseCell(h H3Index) int

BaseCell returns the integer ID of the base cell the H3Index `h` belongs to.

func CellAreaKm2 added in v3.7.1

func CellAreaKm2(h H3Index) float64

CellAreaKm2 returns the exact area of specific cell in square kilometers.

func CellAreaM2 added in v3.7.1

func CellAreaM2(h H3Index) float64

CellAreaM2 returns the exact area of specific cell in square meters.

func CellAreaRads2 added in v3.7.1

func CellAreaRads2(h H3Index) float64

CellAreaRads2 returns the exact area of specific cell in square radians.

func DistanceBetween added in v3.7.1

func DistanceBetween(origin, dest H3Index) int

DistanceBetween returns the distance in grid cells between the two indexes

func EdgeLengthKm added in v3.7.1

func EdgeLengthKm(resolution int) float64

EdgeLengthKm returns the average hexagon edge length in kilometers at the given resolution.

func EdgeLengthM added in v3.7.1

func EdgeLengthM(resolution int) float64

EdgeLengthM returns the average hexagon edge length in meters at the given resolution.

func ExactEdgeLengthKm added in v3.7.1

func ExactEdgeLengthKm(h H3Index) float64

ExactEdgeLengthKm returns the exact edge length of specific unidirectional edge in kilometers.

func ExactEdgeLengthM added in v3.7.1

func ExactEdgeLengthM(h H3Index) float64

ExactEdgeLengthM returns the exact edge length of specific unidirectional edge in meters.

func ExactEdgeLengthRads added in v3.7.1

func ExactEdgeLengthRads(h H3Index) float64

ExactEdgeLengthRads returns the exact edge length of specific unidirectional edge in radians.

func GetFaces added in v3.7.1

func GetFaces(h H3Index) []int

GetFaces returns all icosahedron faces intersected by a given H3 index

func HexAreaKm2 added in v3.7.1

func HexAreaKm2(resolution int) float64

HexAreaKm2 returns the average hexagon area in square kilometers at the given resolution.

func HexAreaM2 added in v3.7.1

func HexAreaM2(resolution int) float64

HexAreaM2 returns the average hexagon area in square meters at the given resolution.

func HexRangeDistances

func HexRangeDistances(origin H3Index, k int) ([][]H3Index, error)

HexRangeDistances implements the C function `hexRangeDistances`.

func HexRanges

func HexRanges(origins []H3Index, k int) ([][]H3Index, error)

HexRanges implements the C function `hexRanges`.

func IsPentagon

func IsPentagon(h H3Index) bool

IsPentagon returns true if `h` is a pentagon.

func IsResClassIII

func IsResClassIII(h H3Index) bool

IsResClassIII returns true if `h` is a class III index. If false, `h` is a class II index.

func IsValid

func IsValid(h H3Index) bool

IsValid returns true if `h` is valid.

func KRingDistances

func KRingDistances(origin H3Index, k int) [][]H3Index

KRingDistances implements the C function `kRingDistances`.

func MaxFaceCount added in v3.7.1

func MaxFaceCount(h H3Index) int

MaxFaceCount returns the maximum number of icosahedron faces the given H3 index may intersect.

func NumHexagons added in v3.7.1

func NumHexagons(resolution int) int

NumHexagons returns the number of unique H3 indexes at the given resolution.

func PentagonIndexCount added in v3.7.1

func PentagonIndexCount() int

PentagonIndexCount returns the number of pentagon H3 indexes per resolution (This is always 12)

func PointDistKm added in v3.7.1

func PointDistKm(a, b GeoCoord) float64

PointDistKm returns the "great circle" or "haversine" distance between pairs of GeoCoord points (lat/lng pairs) in kilometers.

func PointDistM added in v3.7.1

func PointDistM(a, b GeoCoord) float64

PointDistM returns the "great circle" or "haversine" distance between pairs of GeoCoord points (lat/lng pairs) in meters.

func PointDistRads added in v3.7.1

func PointDistRads(a, b GeoCoord) float64

PointDistRads returns the "great circle" or "haversine" distance between pairs of GeoCoord points (lat/lng pairs) in radians.

func Res0IndexCount added in v3.7.1

func Res0IndexCount() int

Res0IndexCount returns the number of resolution 0 H3 indexes.

func Resolution

func Resolution(h H3Index) int

Resolution returns the resolution of `h`.

func ToString

func ToString(h H3Index) string

ToString returns a string representation of an H3Index.

func UnidirectionalEdgeIsValid

func UnidirectionalEdgeIsValid(edge H3Index) bool

UnidirectionalEdgeIsValid returns true if `edge` is a valid unidirectional edge index.

Types

type GeoBoundary

type GeoBoundary []GeoCoord

GeoBoundary is a slice of `GeoCoord`. Note, `len(GeoBoundary)` will never exceed `MaxCellBndryVerts`.

func ToGeoBoundary

func ToGeoBoundary(h H3Index) GeoBoundary

ToGeoBoundary returns a `GeoBoundary` of the H3Index `h`.

func UnidirectionalEdgeBoundary

func UnidirectionalEdgeBoundary(edge H3Index) GeoBoundary

UnidirectionalEdgeBoundary returns the geocoordinates of a unidirectional edge boundary.

type GeoCoord

type GeoCoord struct {
	Latitude, Longitude float64
}

GeoCoord is a struct for geographic coordinates.

func ToGeo

func ToGeo(h H3Index) GeoCoord

ToGeo returns the geographic centerpoint of an H3Index `h`.

type GeoPolygon

type GeoPolygon struct {
	// Geofence is the exterior boundary of the polygon
	Geofence []GeoCoord

	// Holes is a slice of interior boundary (holes) in the polygon
	Holes [][]GeoCoord
}

GeoPolygon is a geofence with 0 or more geofence holes

type H3Index

type H3Index = C.H3Index

H3Index is a type alias for the C type `H3Index`. Effectively H3Index is a `uint64`.

func Compact

func Compact(in []H3Index) []H3Index

Compact merges full sets of children into their parent `H3Index` recursively, until no more merges are possible.

func DestinationFromUnidirectionalEdge

func DestinationFromUnidirectionalEdge(edge H3Index) H3Index

DestinationFromUnidirectionalEdge returns the destination of a unidirectional edge.

func FromGeo

func FromGeo(geoCoord GeoCoord, res int) H3Index

FromGeo returns the H3Index at resolution `res` for a geographic coordinate.

Example
geo := GeoCoord{
	Latitude:  37.775938728915946,
	Longitude: -122.41795063018799,
}
resolution := 9
fmt.Printf("%#x\n", FromGeo(geo, resolution))
Output:

0x8928308280fffff

func FromString

func FromString(hStr string) H3Index

FromString returns an H3Index parsed from a string.

func FromUnidirectionalEdge

func FromUnidirectionalEdge(
	edge H3Index,
) (origin, destination H3Index)

FromUnidirectionalEdge returns the origin and destination from a unidirectional edge.

func GetPentagonIndexes added in v3.7.1

func GetPentagonIndexes(resolution int) []H3Index

GetPentagonIndex returns all the pentagon H3 indexes at the specified resolution.

func GetRes0Indexes added in v3.7.1

func GetRes0Indexes() []H3Index

GetRes0Indexes returns all the resolution 0 H3 indexes.

func HexRange

func HexRange(origin H3Index, k int) ([]H3Index, error)

HexRange implements the C function `hexRange`.

func HexRing

func HexRing(origin H3Index, k int) ([]H3Index, error)

HexRing implements the C function `hexRing`.

func KRing

func KRing(origin H3Index, k int) []H3Index

KRing implements the C function `kRing`.

func Line added in v3.7.0

func Line(start, end H3Index) []H3Index

Line returns the line of h3 indexes connecting two indexes

func OriginFromUnidirectionalEdge

func OriginFromUnidirectionalEdge(edge H3Index) H3Index

OriginFromUnidirectionalEdge returns the origin of a unidirectional edge.

func Polyfill

func Polyfill(gp GeoPolygon, res int) []H3Index

Polyfill returns the hexagons at the given resolution whose centers are within the geofences given in the GeoPolygon struct.

func ToCenterChild added in v3.7.1

func ToCenterChild(h H3Index, resolution int) H3Index

ToCenterChild returns the center child (finer) index contained by h at resolution.

func ToChildren

func ToChildren(parent H3Index, childRes int) []H3Index

ToChildren returns all the `H3Index`es of `parent` at resolution `childRes`. `childRes` must be larger than the resolution of `parent`.

func ToParent

func ToParent(child H3Index, parentRes int) (parent H3Index)

ToParent returns the `H3Index` of the cell that contains `child` at resolution `parentRes`. `parentRes` must be less than the resolution of `child`.

func ToUnidirectionalEdges

func ToUnidirectionalEdges(h H3Index) []H3Index

ToUnidirectionalEdges returns the six (or five if pentagon) unidirectional edges from `h` to each of `h`'s neighbors.

func Uncompact

func Uncompact(in []H3Index, res int) ([]H3Index, error)

Uncompact splits every `H3Index` in `in` if its resolution is greater than `res` recursively. Returns all the `H3Index`es at resolution `res`.

func UnidirectionalEdge

func UnidirectionalEdge(origin, destination H3Index) H3Index

UnidirectionalEdge returns a unidirectional `H3Index` from `origin` to `destination`.

type LinkedGeoCoord added in v3.7.0

type LinkedGeoCoord struct {
	Vertex GeoCoord
	Next   *LinkedGeoCoord
}

type LinkedGeoLoop added in v3.7.0

type LinkedGeoLoop struct {
	First *LinkedGeoCoord
	Last  *LinkedGeoCoord
	Next  *LinkedGeoLoop
}

type LinkedGeoPolygon added in v3.7.0

type LinkedGeoPolygon struct {
	First *LinkedGeoLoop
	Last  *LinkedGeoLoop
	Next  *LinkedGeoPolygon
}

func SetToLinkedGeo added in v3.7.0

func SetToLinkedGeo(in []H3Index) LinkedGeoPolygon

SetToLinkedGeo returns a LinkedGeoPolygon describing the outlines of a set of hexagons

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL