geohash

package
v2.32.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT, MIT Imports: 1 Imported by: 2

README

This is a (selected) copy of github.com/mmcloughlin/geohash with the latitude range changed from 90 to ~85, to align with the algorithm use by Redis.

Documentation

Overview

Package geohash provides encoding and decoding of string and integer geohashes.

Index

Constants

View Source
const (
	ENC_LAT  = 85.05112878
	ENC_LONG = 180.0
)

Variables

This section is empty.

Functions

func DecodeCenter

func DecodeCenter(hash string) (lat, lng float64)

DecodeCenter decodes the string geohash to the central point of the bounding box.

func DecodeInt

func DecodeInt(hash uint64) (lat, lng float64)

DecodeInt decodes the provided 64-bit integer geohash to a (lat, lng) point.

func DecodeIntWithPrecision

func DecodeIntWithPrecision(hash uint64, bits uint) (lat, lng float64)

DecodeIntWithPrecision decodes the provided integer geohash with bits of precision to a (lat, lng) point.

func Encode

func Encode(lat, lng float64) string

Encode the point (lat, lng) as a string geohash with the standard 12 characters of precision.

func EncodeInt

func EncodeInt(lat, lng float64) uint64

encodeInt provides a Go implementation of integer geohash. This is the default implementation of EncodeInt, but optimized versions are provided for certain architectures.

func EncodeIntWithPrecision

func EncodeIntWithPrecision(lat, lng float64, bits uint) uint64

EncodeIntWithPrecision encodes the point (lat, lng) to an integer with the specified number of bits.

func EncodeWithPrecision

func EncodeWithPrecision(lat, lng float64, chars uint) string

EncodeWithPrecision encodes the point (lat, lng) as a string geohash with the specified number of characters of precision (max 12).

func Neighbor

func Neighbor(hash string, direction Direction) string

Neighbor returns a geohash string that corresponds to the provided geohash's neighbor in the provided direction

func NeighborInt

func NeighborInt(hash uint64, direction Direction) uint64

NeighborInt returns a uint64 that corresponds to the provided hash's neighbor in the provided direction at 64-bit precision.

func NeighborIntWithPrecision

func NeighborIntWithPrecision(hash uint64, bits uint, direction Direction) uint64

NeighborIntWithPrecision returns a uint64s that corresponds to the provided hash's neighbor in the provided direction at the given precision.

func Neighbors

func Neighbors(hash string) []string

Neighbors returns a slice of geohash strings that correspond to the provided geohash's neighbors.

func NeighborsInt

func NeighborsInt(hash uint64) []uint64

NeighborsInt returns a slice of uint64s that correspond to the provided hash's neighbors at 64-bit precision.

func NeighborsIntWithPrecision

func NeighborsIntWithPrecision(hash uint64, bits uint) []uint64

NeighborsIntWithPrecision returns a slice of uint64s that correspond to the provided hash's neighbors at the given precision.

Types

type Box

type Box struct {
	MinLat float64
	MaxLat float64
	MinLng float64
	MaxLng float64
}

Box represents a rectangle in latitude/longitude space.

func BoundingBox

func BoundingBox(hash string) Box

BoundingBox returns the region encoded by the given string geohash.

func BoundingBoxInt

func BoundingBoxInt(hash uint64) Box

BoundingBoxInt returns the region encoded by the given 64-bit integer geohash.

func BoundingBoxIntWithPrecision

func BoundingBoxIntWithPrecision(hash uint64, bits uint) Box

BoundingBoxIntWithPrecision returns the region encoded by the integer geohash with the specified precision.

func (Box) Center

func (b Box) Center() (lat, lng float64)

Center returns the center of the box.

func (Box) Contains

func (b Box) Contains(lat, lng float64) bool

Contains decides whether (lat, lng) is contained in the box. The containment test is inclusive of the edges and corners.

type Direction

type Direction int

Direction represents directions in the latitute/longitude space.

const (
	North Direction = iota
	NorthEast
	East
	SouthEast
	South
	SouthWest
	West
	NorthWest
)

Cardinal and intercardinal directions

Jump to

Keyboard shortcuts

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