项目作者: crolly

项目描述 :
Unofficial Go port of the Geo Library for Amazon DynamoDB (https://github.com/amazon-archives/dynamodb-geo) using geohash (https://en.wikipedia.org/wiki/Geohash) to easily create and query geospatial data.
高级语言: Go
项目地址: git://github.com/crolly/dyngeo.git
创建时间: 2019-05-27T16:22:55Z
项目社区:https://github.com/crolly/dyngeo

开源协议:Other

下载


DynG(e)o

Unofficial Go port of the Geo Library for Amazon DynamoDB using geohash to easily create and query geospatial data.
The library takes care of managing the geohash indexes and storing item with latitude/longitude pairs.

Install

Fetch the package with

  1. go get github.com/crolly/dyngeo

And import it into your programs with

  1. import "github.com/crolly/dyngeo"

Usage

DynG(e)o Configuration

  1. type DynGeoConfig struct {
  2. TableName string
  3. ConsistentRead bool
  4. HashKeyAttributeName string
  5. RangeKeyAttributeName string
  6. GeoHashAttributeName string
  7. GeoJSONAttributeName string
  8. GeoHashIndexName string
  9. HashKeyLength int8
  10. LongitudeFirst bool
  11. DynamoDBClient *dynamodb.DynamoDB
  12. }

Defines, how DynG(e)o manages the geospatial data, e.g. what the db attribute and index names are as well as setting the geohash key length.
The geohash key length will determine the size of the tiles the planet will be seperated into:

Length Tile Size
1 5,009.4km x 4,992.6km
2 1,252.3km x 624.1km
3 156.5km x 156km
4 39.1km x 19.5km
5 4.9km x 4.9km
6 1.2km x 609.4m
7 152.9m x 152.4m
8 38.2m x 19m
9 4.8m x 4.8m
10 1.2m x 59.5cm
11 14.9cm x 14.9cm
12 3.7cm x 1.9cm

Setting DynamoDBClient *dynamodb.DynamoDB and TableName string is required.

DynG(e)o Instance

func New

  1. func New(config DynGeoConfig) (*DynGeo, error)

Returns a new instance of DynG(e)o managing the geohashing and geospatial db operations.

func PutPoint

  1. func (dg DynGeo) PutPoint(input PutPointInput) (*PutPointOutput, error)

Put a point into the Amazon DynamoDB table. Once put, you cannot update attributes specified in GeoDataManagerConfiguration: hash key, range key, geohash and geoJson. If you want to update these columns, you need to insert a new record and delete the old record.

func BatchWritePoints

  1. func (dg DynGeo) BatchWritePoints(inputs []PutPointInput) (*BatchWritePointOutput, error)

Put a list of points into the Amazon DynamoDB table. Once put, you cannot update attributes specified in GeoDataManagerConfiguration: hash key, range key, geohash and geoJson. If you want to update these columns, you need to insert a new record and delete the old record.

func GetPoint

  1. func (dg DynGeo) GetPoint(input GetPointInput) (*GetPointOutput, error)

Get a point from the Amazon DynamoDB table.

func UpdatePoint

  1. func (dg DynGeo) UpdatePoint(input UpdatePointInput) (*UpdatePointOutput, error)

Update a point data in Amazon DynamoDB table. You cannot update attributes specified in GeoDataManagerConfiguration: hash key, range key, geohash and geoJson. If you want to update these columns, you need to insert a new record and delete the old record.

func DeletePoint

  1. func (dg DynGeo) DeletePoint(input DeletePointInput) (*DeletePointOutput, error)

Delete a point from the Amazon DynamoDB table.

func QueryRadius

  1. func (dg DynGeo) QueryRadius(input QueryRadiusInput, out interface{}) error

Query a circular area constructed by a center point and its radius.

func QueryRectangle

  1. func (dg DynGeo) QueryRectangle(input QueryRectangleInput, out interface{}) error

Query a rectangular area constructed by two points and return all points within the area. Two points need to construct a rectangle from minimum and maximum latitudes and longitudes. If minPoint.Longitude > maxPoint.Longitude, the rectangle spans the 180 degree longitude line.

Getting Started Example

This repository contains a Getting Started example in the folder starbucks-example inspired by James Beswick’s very good blog post about Location-based search results with DynamoDB and Geohash

It uses the US Starbucks locations, loads them into DynamoDB in batches of 25 and then retrieves the the locations of all Starbucks in the radius of 5000 meters surrounding Latitude: 40.7769099, Longitude: -73.9822532.

The example illustrates the general usage as well as a hint of the performance. The radius search constantly needs about 20-30ms with the given dataset (approximately 6500 Starbucks coffee shops in the US).