项目作者: Willyham

项目描述 :
Fill geofences with geohashes
高级语言: Go
项目地址: git://github.com/Willyham/hashfill.git
创建时间: 2017-11-10T11:56:58Z
项目社区:https://github.com/Willyham/hashfill

开源协议:MIT License

下载


GoDoc Go Report Card

Usage

Hashfill is a library for computing the set of geohashes which are contained by a geofence. It can either produce a set
of hashes which are completely contained or one which also includes where the boundaries intersect. It currently operates on
geom.Polygon objects from the https://github.com/twpayne/go-geom pacakge. Converting from geojson is simple and this
package may offer a utility in the future.

  1. func readFileAsGeometry(t *testing.T, file string) (*geom.Polygon, error) {
  2. data, err := ioutil.ReadFile(file)
  3. if err != nil {
  4. return nil, err
  5. }
  6. poly := new(geom.T)
  7. err = geojson.Unmarshal(data, poly)
  8. if err != nil {
  9. return nil, err
  10. }
  11. return nil, (*poly).(*geom.Polygon)
  12. }
  13. geofence := readFileAsGeometry("testdata/regents.geojson")
  14. filler := hashfill.NewRecursiveFiller(
  15. hashfill.WithMaxPrecision(8),
  16. )
  17. hashes, err := filler.Fill(geofence, hashfill.FillIntersects)

Would result in something that could be visualized as:

Installation

This library depends on headers from the geos library. You can install with brew install geos or dnf install geos-devel on RPM based linux distros.

Options

  • WithMaxPrecision - Sets the max hash precision the algorithm will generate hashes for.
  • WithFixedPrecision - Causes the fully contained geohashes to still be divided into the hashes of the max precision.
  • WithPredicates - Can be used to supply your own functions for Intersect and Contains rather than the built in ones.

Improvements

TODO:

  • [] Fix bug in geofences with holes.
  • [] Corner based check optimisations (+ hybrid)
  • [] Cache poly to geom operation in predicates.
  • [] Add benchmarks