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 ¶
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 ¶
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.