Documentation ¶
Overview ¶
Package geofence provides multiple algorithms for use in geofencing leverages the diglet go library
+build ignore An example stdin implementation
Index ¶
- Constants
- Variables
- func ListenAndServe(addr string, idx FenceIndex, profile bool) error
- func WriteJson(w io.Writer, msg interface{}) (err error)
- type BboxFence
- type BruteFence
- type CityBboxFence
- type CityFence
- type FenceIndex
- type FlatCoverer
- type GeoFence
- type LoopRegion
- type MutexFenceIndex
- func (idx *MutexFenceIndex) Add(name string, feature *geo.Feature) error
- func (idx *MutexFenceIndex) Get(name string) GeoFence
- func (idx *MutexFenceIndex) Keys() []string
- func (idx *MutexFenceIndex) Search(name string, c geo.Coordinate) ([]*geo.Feature, error)
- func (idx *MutexFenceIndex) Set(name string, fence GeoFence)
- type PointGeometry
- type PointMessage
- type Properties
- type Qfence
- type Qrfence
- type ResponseMessage
- type Rfence
- type S2fence
- type UnsafeFenceIndex
- func (idx *UnsafeFenceIndex) Add(name string, feature *geo.Feature) (err error)
- func (idx *UnsafeFenceIndex) Get(name string) (fence GeoFence)
- func (idx *UnsafeFenceIndex) Keys() (keys []string)
- func (idx *UnsafeFenceIndex) Search(name string, c geo.Coordinate) (matchs []*geo.Feature, err error)
- func (idx *UnsafeFenceIndex) Set(name string, fence GeoFence)
Constants ¶
const ( RtreeFence = "rtree" QuadRtreeFence = "qrtree" QuadTreeFence = "qtree" BruteForceFence = "brute" BoundingBoxFence = "bbox" CityBruteFence = "city" CityBoxFence = "city-bbox" S2Fence = "s2" )
Variables ¶
var FenceLabels = []string{ RtreeFence, S2Fence, BruteForceFence, QuadTreeFence, QuadRtreeFence, CityBruteFence, CityBoxFence, BoundingBoxFence, }
Just a list of the fence types
Functions ¶
func ListenAndServe ¶
func ListenAndServe(addr string, idx FenceIndex, profile bool) error
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
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 ¶
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
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)
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.
type LoopRegion ¶ added in v0.0.1
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 ¶
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 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 Qfence ¶
type Qfence struct {
// contains filtered or unexported fields
}
Use an quadtree for segmention. Only inspect geometries whose quad tree leaf contain the query
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 ¶
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
type S2fence ¶ added in v0.0.1
type S2fence struct {
// contains filtered or unexported fields
}
func NewS2fence ¶ added in v0.0.1
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)