• Stars
    star
    525
  • Rank 84,404 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 9 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Golang geohash library

geohash

Go geohash library offering encoding and decoding for string and integer geohashes.

go.dev Reference Build status Coverage Go Report Card

Install

Fetch the package with

go get github.com/mmcloughlin/geohash

And import it into your programs with

import "github.com/mmcloughlin/geohash"

Usage

func ConvertIntToString

func ConvertIntToString(hash uint64, chars uint) string

ConvertIntToString converts an integer geohash to the equivalent string geohash with chars characters. The provided integer geohash is interpreted to have 5*chars bits of precision.

func ConvertStringToInt

func ConvertStringToInt(hash string) (uint64, uint)

ConvertStringToInt converts a string geohash to the equivalent integer geohash. Returns the integer hash and its precision.

func Decode

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

Decode the string geohash to a (lat, lng) point.

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 encodes the point (lat, lng) to a 64-bit integer geohash.

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.

func Validate

func Validate(hash string) error

Validate the string geohash.

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.

func (Box) Round

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

Round returns a point inside the box, making an effort to round to minimal precision.

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

More Repositories

1

avo

Generate x86 Assembly with Go
Go
2,704
star
2

globe

Globe wireframe visualizations in Golang
Go
1,591
star
3

mathfmt

Document mathematical Go code beautifully
Go
197
star
4

addchain

Cryptographic Addition Chain Generation in Go
Go
184
star
5

meow

Meow hash for Golang
Go
124
star
6

profile

Simple profiling for Go
Go
76
star
7

pearl

Tor relay implementation in Golang
Go
75
star
8

cryptofuzz

Fuzzing Go crypto
Go
73
star
9

finsky

Google Play API for Python
Python
57
star
10

ec3

Elliptic Curve Cryptography Compiler: an incomplete experiment in code-generation for elliptic curves in Go
Go
55
star
11

luhn

Generate and verify Luhn check digits
Python
43
star
12

reprotobuf

Reverse engineer protobuf from javanano
Python
29
star
13

professor

Safer interface to Golang net/http/pprof
Go
23
star
14

spherand

Random points on a sphere in Golang
Go
22
star
15

trunnel

Code generator for binary parsing
Go
19
star
16

hellollvm

Basic LLVM passes
C++
17
star
17

md4

Assembly-optimized MD4 hash algorithm in Go
Go
17
star
18

problems

Programming problems
Go
15
star
19

starbucks

All starbucks locations in the world
Python
15
star
20

torcerts

Tor relay certificate downloader
Python
11
star
21

gophercon

Notes from Gophercon
11
star
22

deconstructedgeohash

Supporting code for Geohash Assembly blog post
C++
10
star
23

geohashbench

Benchmarks to compare golang geohash implementations
Go
10
star
24

cpudb

CPUID database derived from InstLatx64
Go
10
star
25

supercomputing

Notes from Supercomputing Conference
10
star
26

garble

Randomize your data
Python
9
star
27

databundler

Embed CSV data in a Golang package
Go
9
star
28

openflights

OpenFlights data in Golang format
Go
9
star
29

iacago

Intel IACA Markers for Golang Assembly
Makefile
9
star
30

goperf

Continuous Benchmarking for the Go compiler
Go
8
star
31

ghr

GitHub recruitment scraper
Go
8
star
32

podium

Convert Golang present talks to PDF
Go
8
star
33

reveal

Reveal source code line-by-line in LaTeX presentations
Python
8
star
34

keepaneyeon

Monitor URLs for changes
Python
8
star
35

aesnix

Experiments with AES-NI performance in Golang
Assembly
7
star
36

ssarules

SSA rules description language in the Go compiler
Go
6
star
37

cite

Cite snippets in your godoc
Go
5
star
38

cuptisamples

NVIDIA CUPTI samples mirror.
Shell
4
star
39

bib

BibTeX references for your Go source code
Go
3
star
40

talks

Talks I've given
Python
3
star
41

cpuid

Interface to intel's cpuid instruction.
C
3
star
42

x

Experimental.
Go
2
star
43

adorn

Generate function and decorator types for Golang interfaces
Go
2
star
44

rqc

Redis query compiler
Go
2
star
45

godepex

Exclude packages from godep
Go
2
star
46

random

Utilities to complement Golang's math/rand package
Go
2
star
47

toroulette

Run a random version of tor
Makefile
2
star
48

bugsalsa

Investigating a 32-bit overflow bug in SUPERCOP-derived salsa20 implementations
Go
2
star
49

usgsmaps

Fetch topo maps from USGS
Python
2
star
50

doclint

Experimental C++ Documentation Linter based on Clang LibTooling
C++
1
star