https://github.com/umpc/go-fdbgeo
This package contains tools for building geospatial layers using FoundationDB with Geohash-encoded keys.
https://github.com/umpc/go-fdbgeo
foundationdb geohash geospatial
Last synced: 5 months ago
JSON representation
This package contains tools for building geospatial layers using FoundationDB with Geohash-encoded keys.
- Host: GitHub
- URL: https://github.com/umpc/go-fdbgeo
- Owner: umpc
- License: isc
- Created: 2018-05-26T08:19:00.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-28T23:41:14.000Z (about 8 years ago)
- Last Synced: 2024-06-20T14:24:58.300Z (almost 2 years ago)
- Topics: foundationdb, geohash, geospatial
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-fdbgeo
[](https://godoc.org/github.com/umpc/go-fdbgeo)
[](https://goreportcard.com/report/github.com/umpc/go-fdbgeo)
```sh
go get -u github.com/umpc/go-fdbgeo
```
Package `fdbgeo` contains tools for building geospatial layers using FoundationDB with Geohash-encoded keys.
This package uses its complimentary [`zrange`](https://github.com/umpc/go-zrange) package, for performing geospatial range queries using FoundationDB 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 [here](https://github.com/umpc/go-zrange).
**Note:** As of 5/26/2018, changes from [`apple/foundationdb` PR #408](https://github.com/apple/foundationdb/pull/408) must be applied to use this package, or a runtime panic will occur during subspace encoding.
## Example usage
```go
...
rangeParams := fdbgeo.RadialRangeParams{
Subspace: dir,
Radius: 32.18688,
Latitude: 37.334722,
Longitude: -122.008889,
}
keyRanges := rangeParams.RadialRange()
fdbRangeOptions := fdb.RangeOptions{
Mode: fdb.StreamingModeWantAll,
}
ret, err := db.ReadTransact(func(tr fdb.ReadTransaction) (ret interface{}, e error) {
rangeResults := make([]fdb.RangeResult, len(keyRanges))
for i, keyRange := range keyRanges {
rangeResults[i] = tr.GetRange(keyRange, fdbRangeOptions)
}
var kvList []fdb.KeyValue
for _, rangeResult := range rangeResults {
ri := rangeResult.Iterator()
for ri.Advance() {
kv := ri.MustGet()
geohashID, err := fdbgeo.UnpackUint(kv.Key, -2)
if err != nil {
panic(err)
}
// Running WithinRadius before value parsing may benefit performance,
// though it depends on the data model in use.
if !rangeParams.WithinRadius(geohashID) {
continue
}
kvList = append(kvList, kv)
}
}
return kvList, e
})
...
```
**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](https://web.archive.org/web/20180526044934/https://github.com/yinqiwen/ardb/wiki/Spatial-Index#search).