geo

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: Apache-2.0 Imports: 9 Imported by: 2

README

geo_fencer

Geo fence library

Documentation

Index

Constants

View Source
const (
	EarthRad = 6372800 //meters
	RadToDeg = 180 / math.Pi
	DegToRad = math.Pi / 180
)
View Source
const Dim = 2

Variables

View Source
var (
	RtreeMinChildren = 25
	RtreeMaxChildren = 50
)

Functions

func UnmarshalGeojsonFeature

func UnmarshalGeojsonFeature(raw string) (feature *geojson.Feature, err error)

Types

type Box

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

func NewBox

func NewBox(min, max Coordinate) (box Box, err error)

func (Box) Contains

func (b Box) Contains(coords ...Coordinate) (in bool)

func (Box) NorthEast

func (b Box) NorthEast() Coordinate

func (Box) SouthWest

func (b Box) SouthWest() Coordinate

type Coordinate

type Coordinate struct {
	Lat, Lon float64
}

func (Coordinate) Difference

func (c Coordinate) Difference(o Coordinate) (d Coordinate)

func (Coordinate) Distance

func (cd Coordinate) Distance(od Coordinate) float64

Distance between coordinates in meters

func (Coordinate) String

func (c Coordinate) String() string

func (Coordinate) ToRad

func (c Coordinate) ToRad() Coordinate

func (Coordinate) X

func (c Coordinate) X() float64

func (Coordinate) Y

func (c Coordinate) Y() float64

type DistError

type DistError float64

DistError is an improper distance measurement. It implements the error and is generated when a distance-related assertion fails.

func (DistError) Error

func (err DistError) Error() string

type Feature

type Feature struct {
	ID         interface{}
	Geometry   []*Shape
	Type       string
	Properties map[string]interface{}
}

func GeojsonFeatureAdapter

func GeojsonFeatureAdapter(gj *geojson.Feature) (feature *Feature, err error)

Flatten all the points of a feature into single list. This can hel in identifying which tiles are going to be created

func MakeFeature

func MakeFeature(length int) *Feature

func NewFeature

func NewFeature(geometryType string, geometry ...*Shape) *Feature

func NewLineFeature

func NewLineFeature(geometry ...*Shape) *Feature

func NewPointFeature

func NewPointFeature(geometry ...*Shape) *Feature

func NewPolygonFeature

func NewPolygonFeature(geometry ...*Shape) *Feature

func (*Feature) AddShape

func (f *Feature) AddShape(s *Shape)

func (*Feature) Center

func (f *Feature) Center() (avg Coordinate)

func (*Feature) Contains

func (f *Feature) Contains(c Coordinate) bool

Only checks as exterior ring

func (*Feature) Tags

func (f *Feature) Tags(key string) string

type GeojsonSource

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

func NewGeojsonSource

func NewGeojsonSource(path string, filter []string) *GeojsonSource

func (*GeojsonSource) Publish

func (gj *GeojsonSource) Publish() (features chan *Feature, err error)

type GeometryType

type GeometryType string
const (
	PolygonFeature GeometryType = "polygon"
	LineFeature    GeometryType = "line"
	PointFeature   GeometryType = "point"
)

type Point

type Point [Dim]float64

Point represents a point in 3-dimensional Euclidean space.

func (Point) ToRect

func (p Point) ToRect(tol float64) *Rect

ToRect constructs a rectangle containing p with side lengths 2*tol.

type Rect

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

Rect represents a subset of 3-dimensional Euclidean space of the form [a1, b1] x [a2, b2] x ... x [an, bn], where ai < bi for all 1 <= i <= n.

func NewRect

func NewRect(p Point, lengths [Dim]float64) (r Rect, err error)

NewRect constructs and returns a pointer to a Rect given a corner point and the lengths of each dimension. The point p should be the most-negative point on the rectangle (in every dimension) and every length should be positive.

func (*Rect) String

func (r *Rect) String() string

type Rnode

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

func NewRnode

func NewRnode(shape *Shape, data interface{}) *Rnode

func (*Rnode) Bounds

func (n *Rnode) Bounds() *Rect

implements rtree.Spatial

func (*Rnode) Feature

func (n *Rnode) Feature() *Feature

func (*Rnode) Value

func (n *Rnode) Value() interface{}

type Rtree

type Rtree struct {
	MinChildren int
	MaxChildren int
	// contains filtered or unexported fields
}

Rtree represents an R-tree, a balanced search tree for storing and querying spatial objects. MinChildren/MaxChildren specify the minimum/maximum branching factors.

func NewRtree

func NewRtree() *Rtree

func NewTree

func NewTree(MinChildren, MaxChildren int) *Rtree

NewTree creates a new R-tree instance.

func (*Rtree) Contains

func (r *Rtree) Contains(c Coordinate) []*Rnode

func (*Rtree) Delete

func (tree *Rtree) Delete(obj Spatial) bool

Delete removes an object from the tree. If the object is not found, ok is false; otherwise ok is true.

Implemented per Section 3.3 of "R-trees: A Dynamic Index Structure for Spatial Searching" by A. Guttman, Proceedings of ACM SIGMOD, p. 47-57, 1984.

func (*Rtree) Depth

func (tree *Rtree) Depth() int

Depth returns the maximum depth of tree.

func (*Rtree) Insert

func (tree *Rtree) Insert(obj Spatial)

Insert inserts a spatial object into the tree. If insertion causes a leaf node to overflow, the tree is rebalanced automatically.

Implemented per Section 3.2 of "R-trees: A Dynamic Index Structure for Spatial Searching" by A. Guttman, Proceedings of ACM SIGMOD, p. 47-57, 1984.

func (*Rtree) Intersections

func (r *Rtree) Intersections(q *Shape) []*Rnode

func (*Rtree) NearestNeighbor

func (tree *Rtree) NearestNeighbor(p Point) Spatial

NearestNeighbor returns the closest object to the specified point. Implemented per "Nearest Neighbor Queries" by Roussopoulos et al

func (*Rtree) NearestNeighbors

func (tree *Rtree) NearestNeighbors(k int, p Point) []Spatial

func (*Rtree) SearchIntersect

func (tree *Rtree) SearchIntersect(bb *Rect) []Spatial

SearchIntersectBB returns all objects that intersect the specified rectangle.

Implemented per Section 3.1 of "R-trees: A Dynamic Index Structure for Spatial Searching" by A. Guttman, Proceedings of ACM SIGMOD, p. 47-57, 1984.

func (*Rtree) Size

func (tree *Rtree) Size() int

Size returns the number of objects currently stored in tree.

func (*Rtree) String

func (tree *Rtree) String() string

type Shape

type Shape struct {
	Coordinates []Coordinate
}

func MakeShape

func MakeShape(length int) *Shape

func NewShape

func NewShape(coords ...Coordinate) *Shape

func ShapeFromString

func ShapeFromString(raw string) (shp *Shape, err error)

[[lon,lat]...]

func (*Shape) Add

func (s *Shape) Add(c ...Coordinate)

func (*Shape) Append

func (s *Shape) Append(o *Shape)

func (*Shape) BoundingBox

func (s *Shape) BoundingBox() Box

func (*Shape) Contains

func (s *Shape) Contains(c Coordinate) bool

func (*Shape) Edges

func (s *Shape) Edges() <-chan []Coordinate

func (*Shape) Head

func (s *Shape) Head() Coordinate

func (*Shape) IsClockwise

func (s *Shape) IsClockwise() bool

func (*Shape) IsClosed

func (s *Shape) IsClosed() bool

Only shapes that contain an area can be closed (>3 Coordinates)

func (*Shape) Length

func (s *Shape) Length() int

Number of coordinates

func (*Shape) Reverse

func (s *Shape) Reverse()

func (*Shape) Tail

func (s *Shape) Tail() Coordinate

type Spatial

type Spatial interface {
	Bounds() *Rect
}

Any type that implements Spatial can be stored in an Rtree and queried.

Jump to

Keyboard shortcuts

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