package module
v0.0.0-...-36dbb96 Latest Latest

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

Go to latest
Published: Feb 26, 2017 License: MIT Imports: 14 Imported by: 3



Build Status    Godoc Reference

Building block for building geospatial indexes using geohashes.


  • Use the Geohash algorithm to index and search data.
  • Index (lat, lng, ID) data in a kv file.
  • Find nearest neighbors from lag, lng within a given radius sorted by distance.
  • Don't designed to store data (should be handled by another component).




This section is empty.


View Source
var (
	Log               = log.New()
	ErrNotFound       = errors.New("key does not exist")
	ErrMissingID      = errors.New("missing ID")
	ErrInvalidLatLong = errors.New("invalid lat/long")


This section is empty.


type Point

type Point struct {
	ID      string
	Geohash string

	// These fields are computed query time and will be ignored when indexing
	Distance float64
	Lat, Lng float64

func NewPointFromGeohash

func NewPointFromGeohash(id, geohash string) *Point

func (*Point) DistanceFrom

func (p *Point) DistanceFrom(point *Point) float64

Implements the equirectangular approximation from www.movable-type.co.uk/scripts/latlong.html (Pythagoras’ theorem on an equirectangular projection)

Returns the approximate distance in meters

type RawGeo

type RawGeo struct {
	// contains filtered or unexported fields

func New

func New(path string) (*RawGeo, error)

New initializes/loads a `RawGeo` index at the given path

func (*RawGeo) Close

func (rg *RawGeo) Close() error

Close gracefully closes the opened index

func (*RawGeo) Destroy

func (rg *RawGeo) Destroy() error

Destroy will try to remove the index file

func (*RawGeo) Index

func (rg *RawGeo) Index(point *Point) error

Put index the given entry in the given index (you have to care about duplicate IDs)

func (*RawGeo) Query

func (rg *RawGeo) Query(lat, lng, radius float64) ([]*Point, error)

Query will returns all the points found in the given radius (in meters) sorted by distance to the query


Path Synopsis

Jump to

Keyboard shortcuts

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