zrange

package module
v0.0.0-...-38ec0ac Latest Latest
Warning

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

Go to latest
Published: May 28, 2018 License: ISC Imports: 3 Imported by: 1 module, 1 package

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-zrange

GoDoc Go Report Card

go get -u github.com/umpc/go-zrange

Package zrange implements an efficient algorithm for performing geospatial range queries with Geohash-encoded keys and a search radius.

The RadialRange method appears to be sufficient for range queries of around 5,000km or less. Changes that efficiently add support for larger query ranges are welcome.

Example usage

...

rangeParams := zrange.RadialRangeParams{
  Radius:    32.18688,
  Latitude:  37.334722,
  Longitude: -122.008889,
}

keyRanges := rangeParams.RadialRange()

...

Note: Geohash range searches are imprecise. Results should be filtered using the input radius where precision is desired.

References

  • The RadialRange method was inspired by the algorithm in the "Search" section of this page.

Documentation

Overview

Package zrange implements an efficient algorithm for performing geospatial range queries with Geohash-encoded keys and a search radius.

The RadialRange method appears to be sufficient for range queries of around 5,000km or less. Changes that efficiently add support for larger query ranges are welcome.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Haversine

func Haversine(lat1, lng1, lat2, lng2 float64) float64

Haversine returns the great circle distance between two latitude/longitude points in kilometers.

Derived from: https://web.archive.org/web/20180528040024/https://community.esri.com/groups/coordinate-reference-systems/blog/2017/10/05/haversine-formula

Types

type HashRange

type HashRange struct {
	Min, Max uint64
}

HashRange contains a minimum and maximum Geohash integer range value.

type HashRanges

type HashRanges []HashRange

HashRanges is a list of ranges containing minimum and maximum Geohash integers, used for performing range queries.

func (HashRanges) CombineRanges

func (hashRangeList HashRanges) CombineRanges() HashRanges

CombineRanges merges each overlapping range. The input list of hash ranges are expected to be sorted in ascending order by their items' Min fields. SetDefaults, and typically FindNeighborsWithRadius and SortMinAsc, should be called before use. RadialRange should be used instead of calling this method directly, unless more customized behavior is desired.

func (HashRanges) SortMinAsc

func (hashRangeList HashRanges) SortMinAsc() HashRanges

SortMinAsc sorts a list of hash ranges in ascending order by their items' Min fields. SetDefaults, and typically FindNeighborsWithRadius, should be called before use. RadialRange should be used instead of calling this method directly, unless more customized behavior is desired.

type RadialRangeParams

type RadialRangeParams struct {
	BitsOfPrecision uint
	Radius,
	Latitude,
	Longitude float64
}

RadialRangeParams defaults to expecting 64-bit Geohash-encoded keys.

func (RadialRangeParams) FindNeighborsWithRadius

func (params RadialRangeParams) FindNeighborsWithRadius() HashRanges

FindNeighborsWithRadius uses the radius and coordinates to find neighboring hash ranges. SetDefaults should be called before use. RadialRange should be used instead of calling this method directly, unless more customized behavior is desired.

func (RadialRangeParams) RadialRange

func (params RadialRangeParams) RadialRange() HashRanges

RadialRange uses a radius in kilometers, a latitude, and a longitude to return a slice of one or more ranges of keys that can be used to efficiently perform Geohash-based spatial queries.

This method uses an algorithm that was derived from the "Search" section of this page: https://web.archive.org/web/20180526044934/https://github.com/yinqiwen/ardb/wiki/Spatial-Index#search

RadialRange expands upon the ideas referenced above, by:

• Sorting key ranges

• Combining overlapping key ranges

• Handling overflows resulting from bitshifting, such as when querying for: (-90, -180)

func (RadialRangeParams) SetDefaults

func (params RadialRangeParams) SetDefaults() RadialRangeParams

SetDefaults sets the default values for the RadialRangeParams type.

func (RadialRangeParams) WithinRadius

func (params RadialRangeParams) WithinRadius(geohashID uint64) bool

WithinRadius determines whether a Geohash is within the specified radius. Its potential benefits are dependent on the data model in use.

Jump to

Keyboard shortcuts

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