import "github.com/dhconnelly/rtreego"
A library for efficiently storing and querying spatial data.
type DimError struct {
Expected int
Actual int
}DimError represents a failure due to mismatched dimensions.
func (err DimError) Error() string
type DistError float64
DistError is an improper distance measurement. It implements the error and is generated when a distance-related assertion fails.
func (err DistError) Error() string
type Point []float64
Point represents a point in n-dimensional Euclidean space.
func (p Point) ToRect(tol float64) *Rect
ToRect constructs a rectangle containing p with side lengths 2*tol.
type Rect struct {
// contains filtered or unexported fields
}Rect represents a subset of n-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(p Point, lengths []float64) (*Rect, 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 (r *Rect) String() string
type Rtree struct {
Dim int
MinChildren int
MaxChildren int
// contains filtered or unexported fields
}Rtree represents an R-tree, a balanced search tree for storing and querying spatial objects. Dim specifies the number of spatial dimensions and MinChildren/MaxChildren specify the minimum/maximum branching factors.
func NewTree(Dim, MinChildren, MaxChildren int) *Rtree
NewTree creates a new R-tree instance.
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. A DimError is returned if the specified object has improper dimensions for the tree.
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 (tree *Rtree) Depth() int
Depth returns the maximum depth of tree.
func (tree *Rtree) Insert(obj Spatial)
Insert inserts a spatial object into the tree. A DimError is returned if the dimensions of the object don't match those of 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 (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 (tree *Rtree) NearestNeighbors(k int, p Point) []Spatial
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 (tree *Rtree) Size() int
Size returns the number of objects currently stored in tree.
func (tree *Rtree) String() string
type Spatial interface {
Bounds() *Rect
}Any type that implements Spatial can be stored in an Rtree and queried.