README

RawGeo

Build Status    Godoc Reference

Building block for building geospatial indexes using geohashes.

Features

  • 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).
Expand ▾ Collapse ▴

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

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

Source Files

Directories

Path Synopsis
example