Help us shape the future of Go! Take the 2026 Go Developer Survey

hashfill

package module
v0.0.0-...-b798a51 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: MIT Imports: 3 Imported by: 0

README

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.

geofence := readFileAsGeometry("testdata/regents.geojson")
filler := hashfill.NewRecursiveFiller(
  hashfill.WithMaxPrecision(8),
)

hashes, err := filler.Fill(geofence, hashfill.FillIntersects)

Would result in something that could be visualized as:

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Contains = containsFunc(func(geofence *geom.Polygon, hash string) (bool, error) {
	hashGeo := hashToGeometry(hash)
	fence := polygonToGeometry(geofence)
	return fence.Contains(hashGeo)
})

Contains tests if the geofence contains the hash by doing a geos contains.

View Source
var Intersects = intersectsFunc(func(geofence *geom.Polygon, hash string) (bool, error) {
	hashGeo := hashToGeometry(hash)
	fence := polygonToGeometry(geofence)
	return fence.Intersects(hashGeo)
})

Intersects tests if the geofence contains the hash by doing a geos intersection.

Functions

This section is empty.

Types

type Container

type Container interface {
	Contains(*geom.Polygon, string) (bool, error)
}

Container tests if a hash is contained.

type FillMode

type FillMode int

FillMode is used to set how the geofence should be filled.

const (
	FillIntersects FillMode = 1
	FillContains   FillMode = 2
)

possible modes are intersects and contains.

type Filler

type Filler interface {
	Fill(*geom.Polygon, FillMode) ([]string, error)
}

Filler is anything which can fill a polygon with geohashes.

type Intersector

type Intersector interface {
	Intersects(*geom.Polygon, string) (bool, error)
}

Intersector tests if a hash intersects.

type Option

type Option func(*RecursiveFiller)

Option allows options to be passed to RecursiveFiller

func WithFixedPrecision

func WithFixedPrecision() Option

WithFixedPrecision makes the filler fill to a fixed precision rather than a variable one.

func WithMaxPrecision

func WithMaxPrecision(p int) Option

WithMaxPrecision sets the highest precision we'll fill to. Defaults to 6.

func WithPredicates

func WithPredicates(contains Container, intersects Intersector) Option

WithPredicates overrides the default predicates used for geometric tests.

type RecursiveFiller

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

RecursiveFiller fills the geofence by recursively searching for the largest geofence which is matched by the intersecting/contains predicate.

func NewRecursiveFiller

func NewRecursiveFiller(options ...Option) *RecursiveFiller

NewRecursiveFiller creates a new filler with the given options.

func (RecursiveFiller) Fill

func (f RecursiveFiller) Fill(fence *geom.Polygon, mode FillMode) ([]string, error)

Fill fills the polygon with geohashes. It works by computing a set of variable length geohashes which are contained in the polygon, then optionally extending those hashes out to the specified precision.

Jump to

Keyboard shortcuts

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