geocollection

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

README

Location-Based Collection for Go

GoDoc Build Status codecov Go Report Card

geocollection builds on top of Google's S2 Library to provide a location-based collection for Go. With this library you can store data based on latitude and longitude. Once it is stored, you may retrieve items within a specific distance by supplying another latitude and longitude.

The library also exposes fine-grained controls over the covering parameters used by S2 to provide maximum performance tuning.

API documentation and examples can be found in the GoDoc.

License

Apache 2

Documentation

Overview

Package geocollection provides a data structure for storing and quickly searching for items based on geographic coordinates on Earth.

Index

Constants

View Source
const EarthRadiusMeters = 6371008.8

EarthRadiusMeters is an approximate representation of the earth's radius in meters.

Variables

This section is empty.

Functions

func EarthDistanceMeters

func EarthDistanceMeters(p1, p2 s2.Point) float64

EarthDistanceMeters calculates the distance in meters between two points on the surface of the Earth

func NewPointFromLatLng

func NewPointFromLatLng(latitude, longitude float64) s2.Point

NewPointFromLatLng constructs an s2 point from a lat/lon ordered pair

Types

type Collection added in v0.2.0

type Collection struct {
	// contains filtered or unexported fields
}

Collection implements the GeoLocationCollection interface and provides a location based cache

func NewCollection added in v0.2.0

func NewCollection() Collection

NewCollection creates a new collection

func (Collection) Delete added in v0.2.0

func (c Collection) Delete(key interface{})

Delete removes an item by its key from the collection.

func (Collection) ItemByKey added in v0.3.0

func (c Collection) ItemByKey(key interface{}) interface{}

ItemByKey returns the contents stored in the collection by its key instead of by a geolocation lookup

func (Collection) ItemsWithinDistance added in v0.2.0

func (c Collection) ItemsWithinDistance(
	latitude, longitude, distanceMeters float64, params SearchCoveringParameters,
) ([]interface{}, SearchCoveringResult)

ItemsWithinDistance returns all contents stored in the collection within distanceMeters radius from the provided latitude an longitude. Note that this is an approximation and items further than distanceMeters may be returned, but it is guaranteed that all item ids returned are within distanceMeters. The caller of this function must specify all parameters used to generate cell covering as well as whether or not the coverer will use the standard covering algorithm or the fast covering algorithm which may be less precise.

func (Collection) Set added in v0.2.0

func (c Collection) Set(key, contents interface{}, latitude, longitude float64)

Set adds an item with a given key to the geo collection at a particular latitude and longitude. If the given key already exists in the collection, it is created, otherwise the contents and location is updated to the new values.

type LocationCollection added in v0.2.0

type LocationCollection interface {
	Set(key, contents interface{}, latitude, longitude float64)
	Delete(key interface{})
	ItemsWithinDistance(latitude, longitude, distanceMeters float64, params SearchCoveringParameters) ([]interface{}, SearchCoveringResult)
	ItemByKey(key interface{}) interface{}
}

LocationCollection defines the interface for interacting with Geo-based collections

type SearchCoveringParameters

type SearchCoveringParameters struct {
	LevelMod        int  `json:"level_mod"`
	MaxCells        int  `json:"max_cells"`
	MaxLevel        int  `json:"max_level"`
	MinLevel        int  `json:"min_level"`
	UseFastCovering bool `json:"use_fast_covering"`
}

SearchCoveringParameters controls the algorithm and parameters used by S2 to determine the covering for the requested search area

type SearchCoveringResult

type SearchCoveringResult [][][]float64

SearchCoveringResult are the boundaries of the cells used in the requested search

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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