rtreego: github.com/dhconnelly/rtreego Index | Files

package rtreego

import "github.com/dhconnelly/rtreego"

A library for efficiently storing and querying spatial data.

Index

type DimError

type DimError struct {
    Expected int
    Actual   int
}

DimError represents a failure due to mismatched dimensions.

func (DimError) Error

func (err DimError) Error() string

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 Point

type Point []float64

Point represents a point in n-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 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

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 (*Rect) String

func (r *Rect) String() string

type Rtree

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

func NewTree(Dim, MinChildren, MaxChildren int) *Rtree

NewTree creates a new R-tree instance.

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. 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 (*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. 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 (*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 Spatial

type Spatial interface {
    Bounds() *Rect
}

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

Files

geom.go rtree.go

Package rtreego imports 4 packages (graph). Updated 2013-03-22. Refresh.