geofence

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2016 License: MIT Imports: 18 Imported by: 2

Documentation

Overview

Package geofence provides multiple algorithms for use in geofencing leverages the diglet go library

+build ignore An example stdin implementation

Index

Constants

View Source
const (
	RtreeFence       = "rtree"
	QuadRtreeFence   = "qrtree"
	QuadTreeFence    = "qtree"
	BruteForceFence  = "brute"
	BoundingBoxFence = "bbox"
	CityBruteFence   = "city"
	CityBoxFence     = "city-bbox"
	S2Fence          = "s2"
)

Variables

Just a list of the fence types

Functions

func ListenAndServe

func ListenAndServe(addr string, idx FenceIndex, profile bool) error

func WriteJson

func WriteJson(w io.Writer, msg interface{}) (err error)

Writes a msg using json encoding

Types

type BboxFence

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

Checks every feature sequentially, first by bounding box, then geometries

func NewBboxFence

func NewBboxFence() *BboxFence

func (*BboxFence) Add

func (b *BboxFence) Add(f *geo.Feature)

func (*BboxFence) Get

func (b *BboxFence) Get(c geo.Coordinate) []*geo.Feature

type BruteFence

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

Check every feature sequentially, fully inspecting every geometry

func NewBruteFence

func NewBruteFence() *BruteFence

func (*BruteFence) Add

func (b *BruteFence) Add(f *geo.Feature)

func (*BruteFence) Get

func (b *BruteFence) Get(c geo.Coordinate) []*geo.Feature

func (*BruteFence) Size

func (b *BruteFence) Size() int

type CityBboxFence

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

Only for demonstrative purposes Checks the containing city first for inclusion, then features. Checks are BoundingBox, then geometry This requires the NYC_BOROS_PATH envvar to be set to the Borrough Boundaries geojson file It can be found here http://www1.nyc.gov/site/planning/data-maps/open-data/districts-download-metadata.page

func NewCityBboxFence

func NewCityBboxFence() (fence *CityBboxFence, err error)

func (*CityBboxFence) Add

func (u *CityBboxFence) Add(f *geo.Feature)

Features must contain a tag BoroName to match to a burrough

func (*CityBboxFence) Get

func (u *CityBboxFence) Get(c geo.Coordinate) []*geo.Feature

type CityFence

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

func NewCityFence

func NewCityFence() (fence *CityFence, err error)

Only for demonstrative purposes Checks the containing city first for inclusion, then features. Fully inspects each geometry in containing city This requires the NYC_BOROS_PATH envvar to be set to the Borrough Boundaries geojson file It can be found here http://www1.nyc.gov/site/planning/data-maps/open-data/districts-download-metadata.page

func (*CityFence) Add

func (u *CityFence) Add(f *geo.Feature)

Features must contain a tag BoroName to match to a burrough

func (*CityFence) Get

func (u *CityFence) Get(c geo.Coordinate) []*geo.Feature

type FenceIndex

type FenceIndex interface {
	// Set the GeoFence
	Set(name string, fence GeoFence)
	// Get the GeoFence at the key, return nil if doesn't exist
	Get(name string) GeoFence
	// Add a feature to the GeoFence at the key
	Add(name string, feature *geo.Feature) error
	// Search for the coordinate at the key
	Search(name string, c geo.Coordinate) ([]*geo.Feature, error)
	// List the keys of the indexed fences
	Keys() []string
}

FenceIndex is a dictionary of multiple fences. Useful if you have multiple data sets that need to be searched

func LoadFenceIndex

func LoadFenceIndex(dir, fenceType string, zoom int) (fences FenceIndex, err error)

func NewFenceIndex

func NewFenceIndex() FenceIndex

Returns a thread-safe FenceIndex

type FlatCoverer added in v0.0.1

type FlatCoverer struct {
	*s2.RegionCoverer
}

Embeds a s2.RegionCover, but does it's own covering Pick the deepest level and normalize a cellunion The default coverer didn't trim on the boundary...

func NewFlatCoverer added in v0.0.1

func NewFlatCoverer(level int) *FlatCoverer

func (*FlatCoverer) CellUnion added in v0.0.1

func (c *FlatCoverer) CellUnion(r s2.Region) s2.CellUnion

func (*FlatCoverer) Covering added in v0.0.1

func (c *FlatCoverer) Covering(r s2.Region) s2.CellUnion

func (*FlatCoverer) InteriorCellUnion added in v0.0.1

func (c *FlatCoverer) InteriorCellUnion(r s2.Region) s2.CellUnion

func (*FlatCoverer) InteriorCovering added in v0.0.1

func (c *FlatCoverer) InteriorCovering(r s2.Region) s2.CellUnion

type GeoFence

type GeoFence interface {
	// Indexes this feature
	Add(f *geo.Feature)
	// Get all features that contain this coordinate
	Get(c geo.Coordinate) []*geo.Feature
}

Interface for algortithms to implement.

func GetFence

func GetFence(label string, zoom int) (fence GeoFence, err error)

label is a string from FenceLabels Zoom only applies to q-based fences

func NewFence

func NewFence() GeoFence

Get the rtree geofence as a default. This is the most flexible and will meet most cases

type LoopRegion added in v0.0.1

type LoopRegion struct {
	*s2.Loop
}

Making s2.Loop implement s2.Region

func LoopRegionFromPoints added in v0.0.1

func LoopRegionFromPoints(points []s2.Point) *LoopRegion

func (*LoopRegion) CapBound added in v0.0.1

func (l *LoopRegion) CapBound() s2.Cap

func (*LoopRegion) ContainsCell added in v0.0.1

func (l *LoopRegion) ContainsCell(c s2.Cell) bool

func (*LoopRegion) IntersectsCell added in v0.0.1

func (l *LoopRegion) IntersectsCell(c s2.Cell) bool

type MutexFenceIndex

type MutexFenceIndex struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMutexFenceIndex

func NewMutexFenceIndex() *MutexFenceIndex

func (*MutexFenceIndex) Add

func (idx *MutexFenceIndex) Add(name string, feature *geo.Feature) error

func (*MutexFenceIndex) Get

func (idx *MutexFenceIndex) Get(name string) GeoFence

func (*MutexFenceIndex) Keys

func (idx *MutexFenceIndex) Keys() []string

func (*MutexFenceIndex) Search

func (idx *MutexFenceIndex) Search(name string, c geo.Coordinate) ([]*geo.Feature, error)

func (*MutexFenceIndex) Set

func (idx *MutexFenceIndex) Set(name string, fence GeoFence)

type PointGeometry

type PointGeometry struct {
	Type        string    `json:"type"`
	Coordinates []float64 `json:"coordinates"`
}

type PointMessage

type PointMessage struct {
	Type       string        `json:"type"`
	Properties Properties    `json:"properties"`
	Geometry   PointGeometry `json:"geometry"`
}

func UnmarshalPoint

func UnmarshalPoint(raw []byte) (point *PointMessage, err error)

type Properties

type Properties map[string]interface{}

TODO change interface{} -> json.RawMessage

type Qfence

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

Use an quadtree for segmention. Only inspect geometries whose quad tree leaf contain the query

func NewQfence

func NewQfence(zoom int) *Qfence

func (*Qfence) Add

func (q *Qfence) Add(f *geo.Feature)

func (*Qfence) Get

func (q *Qfence) Get(c geo.Coordinate) (matchs []*geo.Feature)

type Qrfence

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

Mutliple rtree segmented by quadtree first, probably only useful in a distributed environment

func NewQrfence

func NewQrfence(zoom int) *Qrfence

func (*Qrfence) Add

func (q *Qrfence) Add(f *geo.Feature)

func (*Qrfence) Get

func (q *Qrfence) Get(c geo.Coordinate) (matchs []*geo.Feature)

type ResponseMessage

type ResponseMessage struct {
	Query  PointMessage `json:"query"`
	Fences []Properties `json:"fences"`
}

func GeojsonSearch

func GeojsonSearch(idx FenceIndex, name string, body []byte) (result ResponseMessage, err error)

Searchs the fence for the contents of body. Body should be a geojson point feature. Returns a json string of the body with a property key 'fences' which is a list of the property object of the features that contain the query.

type Rfence

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

Standard rtree with M=50

func NewRfence

func NewRfence() *Rfence

func (*Rfence) Add

func (r *Rfence) Add(f *geo.Feature)

func (*Rfence) Get

func (r *Rfence) Get(c geo.Coordinate) (matchs []*geo.Feature)

type S2fence added in v0.0.1

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

func NewS2fence added in v0.0.1

func NewS2fence(zoom int) *S2fence

func (*S2fence) Add added in v0.0.1

func (s *S2fence) Add(f *geo.Feature)

func (*S2fence) Get added in v0.0.1

func (s *S2fence) Get(c geo.Coordinate) (matchs []*geo.Feature)

type UnsafeFenceIndex

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

func NewUnsafeFenceIndex

func NewUnsafeFenceIndex() *UnsafeFenceIndex

func (*UnsafeFenceIndex) Add

func (idx *UnsafeFenceIndex) Add(name string, feature *geo.Feature) (err error)

func (*UnsafeFenceIndex) Get

func (idx *UnsafeFenceIndex) Get(name string) (fence GeoFence)

func (*UnsafeFenceIndex) Keys

func (idx *UnsafeFenceIndex) Keys() (keys []string)

func (*UnsafeFenceIndex) Search

func (idx *UnsafeFenceIndex) Search(name string, c geo.Coordinate) (matchs []*geo.Feature, err error)

func (*UnsafeFenceIndex) Set

func (idx *UnsafeFenceIndex) Set(name string, fence GeoFence)

Jump to

Keyboard shortcuts

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