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 ¶
- Constants
- Variables
- func AreNeighbors(h1, h2 H3Index) bool
- func BaseCell(h H3Index) int
- func CellAreaKm2(h H3Index) float64
- func CellAreaM2(h H3Index) float64
- func CellAreaRads2(h H3Index) float64
- func DistanceBetween(origin, dest H3Index) int
- func EdgeLengthKm(resolution int) float64
- func EdgeLengthM(resolution int) float64
- func ExactEdgeLengthKm(h H3Index) float64
- func ExactEdgeLengthM(h H3Index) float64
- func ExactEdgeLengthRads(h H3Index) float64
- func GetFaces(h H3Index) []int
- func HexAreaKm2(resolution int) float64
- func HexAreaM2(resolution int) float64
- func HexRangeDistances(origin H3Index, k int) ([][]H3Index, error)
- func HexRanges(origins []H3Index, k int) ([][]H3Index, error)
- func IsPentagon(h H3Index) bool
- func IsResClassIII(h H3Index) bool
- func IsValid(h H3Index) bool
- func KRingDistances(origin H3Index, k int) [][]H3Index
- func MaxFaceCount(h H3Index) int
- func NumHexagons(resolution int) int
- func PentagonIndexCount() int
- func PointDistKm(a, b GeoCoord) float64
- func PointDistM(a, b GeoCoord) float64
- func PointDistRads(a, b GeoCoord) float64
- func Res0IndexCount() int
- func Resolution(h H3Index) int
- func ToString(h H3Index) string
- func UnidirectionalEdgeIsValid(edge H3Index) bool
- type GeoBoundary
- type GeoCoord
- type GeoPolygon
- type H3Index
- func Compact(in []H3Index) []H3Index
- func DestinationFromUnidirectionalEdge(edge H3Index) H3Index
- func FromGeo(geoCoord GeoCoord, res int) H3Index
- func FromString(hStr string) H3Index
- func FromUnidirectionalEdge(edge H3Index) (origin, destination H3Index)
- func GetPentagonIndexes(resolution int) []H3Index
- func GetRes0Indexes() []H3Index
- func HexRange(origin H3Index, k int) ([]H3Index, error)
- func HexRing(origin H3Index, k int) ([]H3Index, error)
- func KRing(origin H3Index, k int) []H3Index
- func Line(start, end H3Index) []H3Index
- func OriginFromUnidirectionalEdge(edge H3Index) H3Index
- func Polyfill(gp GeoPolygon, res int) []H3Index
- func ToCenterChild(h H3Index, resolution int) H3Index
- func ToChildren(parent H3Index, childRes int) []H3Index
- func ToParent(child H3Index, parentRes int) (parent H3Index)
- func ToUnidirectionalEdges(h H3Index) []H3Index
- func Uncompact(in []H3Index, res int) ([]H3Index, error)
- func UnidirectionalEdge(origin, destination H3Index) H3Index
- type LinkedGeoCoord
- type LinkedGeoLoop
- type LinkedGeoPolygon
Examples ¶
Constants ¶
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 ¶
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 ¶
AreNeighbors returns true if `h1` and `h2` are neighbors. Two indexes are neighbors if they share an edge.
func CellAreaKm2 ¶ added in v3.7.1
CellAreaKm2 returns the exact area of specific cell in square kilometers.
func CellAreaM2 ¶ added in v3.7.1
CellAreaM2 returns the exact area of specific cell in square meters.
func CellAreaRads2 ¶ added in v3.7.1
CellAreaRads2 returns the exact area of specific cell in square radians.
func DistanceBetween ¶ added in v3.7.1
DistanceBetween returns the distance in grid cells between the two indexes
func EdgeLengthKm ¶ added in v3.7.1
EdgeLengthKm returns the average hexagon edge length in kilometers at the given resolution.
func EdgeLengthM ¶ added in v3.7.1
EdgeLengthM returns the average hexagon edge length in meters at the given resolution.
func ExactEdgeLengthKm ¶ added in v3.7.1
ExactEdgeLengthKm returns the exact edge length of specific unidirectional edge in kilometers.
func ExactEdgeLengthM ¶ added in v3.7.1
ExactEdgeLengthM returns the exact edge length of specific unidirectional edge in meters.
func ExactEdgeLengthRads ¶ added in v3.7.1
ExactEdgeLengthRads returns the exact edge length of specific unidirectional edge in radians.
func GetFaces ¶ added in v3.7.1
GetFaces returns all icosahedron faces intersected by a given H3 index
func HexAreaKm2 ¶ added in v3.7.1
HexAreaKm2 returns the average hexagon area in square kilometers at the given resolution.
func HexAreaM2 ¶ added in v3.7.1
HexAreaM2 returns the average hexagon area in square meters at the given resolution.
func HexRangeDistances ¶
HexRangeDistances implements the C function `hexRangeDistances`.
func IsResClassIII ¶
IsResClassIII returns true if `h` is a class III index. If false, `h` is a class II index.
func KRingDistances ¶
KRingDistances implements the C function `kRingDistances`.
func MaxFaceCount ¶ added in v3.7.1
MaxFaceCount returns the maximum number of icosahedron faces the given H3 index may intersect.
func NumHexagons ¶ added in v3.7.1
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
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
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
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 UnidirectionalEdgeIsValid ¶
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.
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 ¶
H3Index is a type alias for the C type `H3Index`. Effectively H3Index is a `uint64`.
func Compact ¶
Compact merges full sets of children into their parent `H3Index` recursively, until no more merges are possible.
func DestinationFromUnidirectionalEdge ¶
DestinationFromUnidirectionalEdge returns the destination of a unidirectional edge.
func FromGeo ¶
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 ¶
FromString returns an H3Index parsed from a string.
func FromUnidirectionalEdge ¶
FromUnidirectionalEdge returns the origin and destination from a unidirectional edge.
func GetPentagonIndexes ¶ added in v3.7.1
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 OriginFromUnidirectionalEdge ¶
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
ToCenterChild returns the center child (finer) index contained by h at resolution.
func ToChildren ¶
ToChildren returns all the `H3Index`es of `parent` at resolution `childRes`. `childRes` must be larger than the resolution of `parent`.
func ToParent ¶
ToParent returns the `H3Index` of the cell that contains `child` at resolution `parentRes`. `parentRes` must be less than the resolution of `child`.
func ToUnidirectionalEdges ¶
ToUnidirectionalEdges returns the six (or five if pentagon) unidirectional edges from `h` to each of `h`'s neighbors.
func Uncompact ¶
Uncompact splits every `H3Index` in `in` if its resolution is greater than `res` recursively. Returns all the `H3Index`es at resolution `res`.
func UnidirectionalEdge ¶
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