geoindex

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2016 License: BSD-3-Clause Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-geoindex

A simple in-memory geoindex for Go, based on the geohash-int library.

Proximity search largely based on the StackExchange discussion: http://gis.stackexchange.com/questions/18330/would-it-be-possible-to-use-geohash-for-proximity-searches/92331#92331

Original geohash-int library: https://github.com/yinqiwen/geohash-int

The modified fork of the geohash-int: https://github.com/mattsta/geohash-int

Some more documentations: https://github.com/yinqiwen/ardb/blob/master/doc/spatial-index.md https://matt.sh/redis-geo#_how-it-works

Usage

Add location:

    prop := []string{"property1", "property2"}
    AddCoord(&GeoData{Latitude: -32.1, Longitude: 120.3, Name: "myLocationName", Properties: &prop})

Search locations at lat/long (-32.1, 120.3) within a 12 km bound:

    locations := SearchBound(-32.2, 120.3, 12)

Get location details by ID. The ID is in the format {geohash}-{name} (included in search results):

    locationId := "3139639761105107-myLocationName"
    GetLocation(locationId)

Limitations

  • Search bounds are approximate square, and become gradually curved as the area increases.
  • Bound distance are approximate and does not take the flat polar region into account.
  • Latitude/Longitude approximation:
    • 1 deg latitude = 110.574 km
    • 1 deg longitude = 111.320*cos(latitude) km
  • This geohash based proximity search does not search across the boundary at the poles (0) and at the international date line (180/-180).
  • Name of location should be unique for the same coordinate.
  • Limited to 100 locations at the same coordinate.

Documentation

Overview

* Copyright (c) 2015, Ian Chan <icha024@gmail.com>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Redis nor the names of its contributors may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

View Source
const MAX_STEPS C.uint8_t = 26

Variables

This section is empty.

Functions

func AddLocation

func AddLocation(provider string, geoData *GeoData)

AddLocation data to search index.

func Debugf

func Debugf(format string, args ...interface{})

Types

type GeoData

type GeoData struct {
	// Must be unique
	Id int
	// Generated automatically
	GeoHash uint64
	// User must specify these
	Latitude, Longitude float64
	Properties          *[]string
}

func GetLocation

func GetLocation(id int) (geodata *GeoData, err error)

GetLocation data for a location ID.

func SearchLocations

func SearchLocations(provider string, latitude, longitude, bound float64) []*GeoData

SearchLocations around latitude/longitude in bounded area (km) for known location points.

type GeoIdSlice

type GeoIdSlice []*GeoData

GeoIdSlice sorted by ID

func (GeoIdSlice) Len

func (s GeoIdSlice) Len() int

func (GeoIdSlice) Less

func (s GeoIdSlice) Less(i, j int) bool

func (GeoIdSlice) Swap

func (s GeoIdSlice) Swap(i, j int)

type GeoSlice

type GeoSlice []*GeoData

GeoSlice sorted by GeoHash

func (GeoSlice) Len

func (s GeoSlice) Len() int

func (GeoSlice) Less

func (s GeoSlice) Less(i, j int) bool

func (GeoSlice) Swap

func (s GeoSlice) Swap(i, j int)

Jump to

Keyboard shortcuts

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