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 BaseCellNumber(h Cell) int
- func CellAreaKm2(c Cell) (float64, error)
- func CellAreaM2(c Cell) (float64, error)
- func CellAreaRads2(c Cell) (float64, error)
- func CellToChildPos(a Cell, resolution int) (int, error)
- func EdgeLengthKm(e DirectedEdge) (float64, error)
- func EdgeLengthM(e DirectedEdge) (float64, error)
- func EdgeLengthRads(e DirectedEdge) (float64, error)
- func GreatCircleDistanceKm(a, b LatLng) float64
- func GreatCircleDistanceM(a, b LatLng) float64
- func GreatCircleDistanceRads(a, b LatLng) float64
- func GridDiskDistances(origin Cell, k int) ([][]Cell, error)
- func GridDistance(a, b Cell) (int, error)
- func HexagonAreaAvgKm2(resolution int) (float64, error)
- func HexagonAreaAvgM2(resolution int) (float64, error)
- func HexagonEdgeLengthAvgKm(resolution int) (float64, error)
- func HexagonEdgeLengthAvgM(resolution int) (float64, error)
- func IndexFromString(s string) uint64
- func IndexToString(i uint64) string
- func IsValidVertex(c Cell) bool
- func NumCells(resolution int) int
- type Cell
- func CellToVertex(c Cell, vertexNum int) (Cell, error)
- func CellToVertexes(c Cell) ([]Cell, error)
- func ChildPosToCell(position int, a Cell, resolution int) (Cell, error)
- func CompactCells(in []Cell) ([]Cell, error)
- func GridDisk(origin Cell, k int) ([]Cell, error)
- func GridPath(a, b Cell) ([]Cell, error)
- func LatLngToCell(latLng LatLng, resolution int) (Cell, error)
- func LocalIJToCell(origin Cell, ij CoordIJ) (Cell, error)
- func Pentagons(resolution int) ([]Cell, error)
- func PolygonToCells(polygon GeoPolygon, resolution int) ([]Cell, error)
- func Res0Cells() ([]Cell, error)
- func UncompactCells(in []Cell, resolution int) ([]Cell, error)
- func (c Cell) BaseCellNumber() int
- func (c Cell) Boundary() (CellBoundary, error)
- func (c Cell) CenterChild(resolution int) (Cell, error)
- func (c Cell) ChildPos(resolution int) (int, error)
- func (c Cell) ChildPosToCell(position int, resolution int) (Cell, error)
- func (c Cell) Children(resolution int) ([]Cell, error)
- func (c Cell) DirectedEdge(other Cell) (DirectedEdge, error)
- func (c Cell) DirectedEdges() ([]DirectedEdge, error)
- func (c Cell) GridDisk(k int) ([]Cell, error)
- func (c Cell) GridDiskDistances(k int) ([][]Cell, error)
- func (c Cell) GridDistance(other Cell) (int, error)
- func (c Cell) GridPath(other Cell) ([]Cell, error)
- func (c Cell) IcosahedronFaces() ([]int, error)
- func (c Cell) ImmediateChildren() ([]Cell, error)
- func (c Cell) ImmediateParent() (Cell, error)
- func (c Cell) IsNeighbor(other Cell) (bool, error)
- func (c Cell) IsPentagon() bool
- func (c Cell) IsResClassIII() bool
- func (c Cell) IsValid() bool
- func (c Cell) LatLng() (LatLng, error)
- func (c Cell) MarshalText() ([]byte, error)
- func (c Cell) Parent(resolution int) (Cell, error)
- func (c Cell) Resolution() int
- func (c Cell) String() string
- func (c *Cell) UnmarshalText(text []byte) error
- type CellBoundary
- type CoordIJ
- type DirectedEdge
- type GeoLoop
- type GeoPolygon
- type LatLng
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 LatLng 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 // The number of H3 pentagon cells (same at every resolution) NumPentagons = C.NUM_PENTAGONS // InvalidH3Index is a sentinel value for an invalid H3 index. InvalidH3Index = C.H3_NULL DegsToRads = math.Pi / 180.0 RadsToDegs = 180.0 / math.Pi )
Variables ¶
var ( ErrFailed = errors.New("the operation failed") ErrDomain = errors.New("argument was outside of acceptable range") ErrLatLngDomain = errors.New("latitude or longitude arguments were outside of acceptable range") ErrResolutionDomain = errors.New("resolution argument was outside of acceptable range") ErrCellInvalid = errors.New("H3Index cell argument was not valid") ErrDirectedEdgeInvalid = errors.New("H3Index directed edge argument was not valid") ErrUndirectedEdgeInvalid = errors.New("H3Index undirected edge argument was not valid") ErrVertexInvalid = errors.New("H3Index vertex argument was not valid") ErrPentagon = errors.New("pentagon distortion was encountered") ErrDuplicateInput = errors.New("duplicate input was encountered in the arguments") ErrNotNeighbors = errors.New("H3Index cell arguments were not neighbors") ErrRsolutionMismatch = errors.New("H3Index cell arguments had incompatible resolutions") ErrMemoryAlloc = errors.New("necessary memory allocation failed") ErrMemoryBounds = errors.New("bounds of provided memory were not large enough") ErrOptionInvalid = errors.New("mode or flags argument was not valid") ErrUnknown = errors.New("unknown error code returned by H3") )
Error codes.
Functions ¶
func BaseCellNumber ¶
BaseCellNumber returns the integer ID (0-121) of the base cell the H3Index h belongs to.
func CellAreaKm2 ¶
CellAreaKm2 returns the exact area of specific cell in square kilometers.
func CellAreaM2 ¶
CellAreaM2 returns the exact area of specific cell in square meters.
func CellAreaRads2 ¶
CellAreaRads2 returns the exact area of specific cell in square radians.
func CellToChildPos ¶ added in v4.1.0
CellToChildPos returns the position of the cell a within an ordered list of all children of the cell's parent at the specified resolution.
func EdgeLengthKm ¶
func EdgeLengthKm(e DirectedEdge) (float64, error)
EdgeLengthKm returns the exact edge length of specific unidirectional edge in kilometers.
func EdgeLengthM ¶
func EdgeLengthM(e DirectedEdge) (float64, error)
EdgeLengthM returns the exact edge length of specific unidirectional edge in meters.
func EdgeLengthRads ¶
func EdgeLengthRads(e DirectedEdge) (float64, error)
EdgeLengthRads returns the exact edge length of specific unidirectional edge in radians.
func GreatCircleDistanceKm ¶
PointDistKm returns the "great circle" or "haversine" distance between pairs of LatLng points (lat/lng pairs) in kilometers.
func GreatCircleDistanceM ¶
PointDistM returns the "great circle" or "haversine" distance between pairs of LatLng points (lat/lng pairs) in meters.
func GreatCircleDistanceRads ¶
PointDistRads returns the "great circle" or "haversine" distance between pairs of LatLng points (lat/lng pairs) in radians.
func GridDiskDistances ¶
GridDiskDistances produces cells within grid distance k of the origin cell.
k-ring 0 is defined as the origin cell, k-ring 1 is defined as k-ring 0 and all neighboring cells, and so on.
Outer slice is ordered from origin outwards. Inner slices are in no particular order. Elements of the output array may be left zero, as can happen when crossing a pentagon.
func GridDistance ¶
func HexagonAreaAvgKm2 ¶
HexAreaKm2 returns the average hexagon area in square kilometers at the given resolution.
func HexagonAreaAvgM2 ¶
HexAreaM2 returns the average hexagon area in square meters at the given resolution.
func HexagonEdgeLengthAvgKm ¶
HexagonEdgeLengthAvgKm returns the average hexagon edge length in kilometers at the given resolution.
func HexagonEdgeLengthAvgM ¶
HexagonEdgeLengthAvgM returns the average hexagon edge length in meters at the given resolution.
func IndexFromString ¶
IndexFromString returns a Cell from a string. Should call c.IsValid() to check if the Cell is valid before using it.
func IndexToString ¶
IndexToString returns a Cell from a string. Should call c.IsValid() to check if the Cell is valid before using it.
func IsValidVertex ¶ added in v4.1.2
Types ¶
type Cell ¶
type Cell int64
Cell is an Index that identifies a single hexagon cell at a resolution.
func CellToVertexes ¶ added in v4.1.2
func ChildPosToCell ¶ added in v4.1.0
ChildPosToCell returns the child of cell a at a given position within an ordered list of all children at the specified resolution.
func CompactCells ¶
CompactCells merges full sets of children into their parent H3Index recursively, until no more merges are possible.
func GridDisk ¶
GridDisk produces cells within grid distance k of the origin cell.
k-ring 0 is defined as the origin cell, k-ring 1 is defined as k-ring 0 and all neighboring cells, and so on.
Output is placed in an array in no particular order. Elements of the output array may be left zero, as can happen when crossing a pentagon.
func LatLngToCell ¶
LatLngToCell returns the Cell at resolution for a geographic coordinate.
Example ¶
latLng := h3.NewLatLng(37.775938728915946, -122.41795063018799) resolution := 9 c, err := h3.LatLngToCell(latLng, resolution) if err != nil { panic(err) } fmt.Printf("%s", c)
Output: 8928308280fffff
func PolygonToCells ¶
func PolygonToCells(polygon GeoPolygon, resolution int) ([]Cell, error)
PolygonToCells takes a given GeoJSON-like data structure fills it with the hexagon cells that are contained by the GeoJSON-like data structure.
This implementation traces the GeoJSON geoloop(s) in cartesian space with hexagons, tests them and their neighbors to be contained by the geoloop(s), and then any newly found hexagons are used to test again until no new hexagons are found.
func UncompactCells ¶
UncompactCells splits every H3Index in in if its resolution is greater than resolution recursively. Returns all the H3Indexes at resolution resolution.
func (Cell) BaseCellNumber ¶
BaseCellNumber returns the integer ID (0-121) of the base cell the H3Index h belongs to.
func (Cell) Boundary ¶
func (c Cell) Boundary() (CellBoundary, error)
Boundary returns a CellBoundary of the Cell.
func (Cell) CenterChild ¶
CenterChild returns the center child Cell of this Cell.
func (Cell) ChildPos ¶ added in v4.1.0
ChildPos returns the position of the cell within an ordered list of all children of the cell's parent at the specified resolution.
func (Cell) ChildPosToCell ¶ added in v4.1.0
ChildPosToCell returns the child cell at a given position within an ordered list of all children at the specified resolution.
func (Cell) DirectedEdge ¶
func (c Cell) DirectedEdge(other Cell) (DirectedEdge, error)
DirectedEdge returns a DirectedEdge from this Cell to other.
func (Cell) DirectedEdges ¶
func (c Cell) DirectedEdges() ([]DirectedEdge, error)
DirectedEdges returns 6 directed edges with h as the origin.
func (Cell) GridDisk ¶
GridDisk produces cells within grid distance k of the origin cell.
k-ring 0 is defined as the origin cell, k-ring 1 is defined as k-ring 0 and all neighboring cells, and so on.
Output is placed in an array in no particular order. Elements of the output array may be left zero, as can happen when crossing a pentagon.
func (Cell) GridDiskDistances ¶
GridDiskDistances produces cells within grid distance k of the origin cell.
k-ring 0 is defined as the origin cell, k-ring 1 is defined as k-ring 0 and all neighboring cells, and so on.
Outer slice is ordered from origin outwards. Inner slices are in no particular order. Elements of the output array may be left zero, as can happen when crossing a pentagon.
func (Cell) IcosahedronFaces ¶
IcosahedronFaces finds all icosahedron faces (0-19) intersected by this Cell.
func (Cell) ImmediateChildren ¶
ImmediateChildren returns the children or grandchildren cells of this Cell.
func (Cell) ImmediateParent ¶
Parent returns the parent or grandparent Cell of this Cell.
func (Cell) IsNeighbor ¶
IsNeighbor returns true if this Cell is a neighbor of the other Cell.
func (Cell) IsPentagon ¶
IsPentagon returns true if this is a pentagon.
func (Cell) IsResClassIII ¶
IsResClassIII returns true if this is a class III index. If false, this is a class II index.
func (Cell) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Cell) Resolution ¶
func (*Cell) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type CellBoundary ¶
type CellBoundary []LatLng
CellBoundary is a slice of LatLng. Note, len(CellBoundary) will never exceed MaxCellBndryVerts.
func CellToBoundary ¶
func CellToBoundary(c Cell) (CellBoundary, error)
CellToBoundary returns a CellBoundary of the Cell.
type DirectedEdge ¶
type DirectedEdge int64
DirectedEdge is an Index that identifies a directed edge between two cells.
func (DirectedEdge) Boundary ¶
func (e DirectedEdge) Boundary() (CellBoundary, error)
Boundary provides the coordinates of the boundary of the directed edge. Note, the type returned is CellBoundary, but the coordinates will be from the center of the origin to the center of the destination. There may be more than 2 coordinates to account for crossing faces.
func (DirectedEdge) Cells ¶
func (e DirectedEdge) Cells() ([]Cell, error)
Cells returns the origin and destination cells in that order.
func (DirectedEdge) Destination ¶
func (e DirectedEdge) Destination() (Cell, error)
Destination returns the destination cell of this directed edge.
func (DirectedEdge) IsValid ¶
func (e DirectedEdge) IsValid() bool
func (DirectedEdge) Origin ¶
func (e DirectedEdge) Origin() (Cell, error)
Origin returns the origin cell of this directed edge.
func (DirectedEdge) Resolution ¶
func (e DirectedEdge) Resolution() int
type GeoPolygon ¶
GeoPolygon is a GeoLoop with 0 or more GeoLoop holes.
func CellsToMultiPolygon ¶
func CellsToMultiPolygon(cells []Cell) ([]GeoPolygon, error)
CellsToMultiPolygon takes a set of cells and creates GeoPolygon(s) describing the outline(s) of a set of hexagons. Polygon outlines will follow GeoJSON MultiPolygon order: Each polygon will have one outer loop, which is first in the list, followed by any holes.
It is expected that all hexagons in the set have the same resolution and that the set contains no duplicates. Behavior is undefined if duplicates or multiple resolutions are present, and the algorithm may produce unexpected or invalid output.
func (GeoPolygon) Cells ¶
func (p GeoPolygon) Cells(resolution int) ([]Cell, error)
PolygonToCells takes a given GeoJSON-like data structure fills it with the hexagon cells that are contained by the GeoJSON-like data structure.
This implementation traces the GeoJSON geoloop(s) in cartesian space with hexagons, tests them and their neighbors to be contained by the geoloop(s), and then any newly found hexagons are used to test again until no new hexagons are found.
type LatLng ¶
type LatLng struct {
Lat, Lng float64
}
LatLng is a struct for geographic coordinates in degrees.
func CellToLatLng ¶
CellToLatLng returns the geographic centerpoint of a Cell.