Documentation ¶
Overview ¶
Package rtree implements an in-memory r-tree data structure. This data structure can be used as a spatial index, allowing fast spatial searches based on a bounding box.
The implementation is heavily based on "R-Trees. A Dynamic Index Structure For Spatial Searching" by Antonin Guttman (which can be found at http://www-db.deis.unibo.it/courses/SI-LS/papers/Gut84.pdf).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Stop = errors.New("stop") //nolint:stylecheck,revive
Stop is a special sentinel error that can be used to stop a search operation without any error.
Functions ¶
This section is empty.
Types ¶
type RTree ¶
type RTree struct {
// contains filtered or unexported fields
}
RTree is an in-memory R-Tree data structure. It holds record ID and bounding box pairs (the actual records aren't stored in the tree; the user is responsible for storing their own records). Its zero value is an empty R-Tree.
func BulkLoad ¶
BulkLoad bulk loads multiple items into a new R-Tree. The bulk load operation is optimised for creating R-Trees with minimal node overlap. This allows for fast searching.
func (*RTree) Extent ¶ added in v0.15.0
Extent gives the Box that most closely bounds the RTree. If the RTree is empty, then false is returned.
func (*RTree) Nearest ¶ added in v0.25.0
Nearest finds the record in the RTree that is the closest to the input box as measured by the Euclidean metric. Note that there may be multiple records that are equidistant from the input box, in which case one is chosen arbitrarily. If the RTree is empty, then false is returned.
func (*RTree) PrioritySearch ¶ added in v0.17.0
PrioritySearch iterates over the records in the RTree in priority order of distance from the input box (shortest distance first using the Euclidean metric). The callback is called for every element iterated over. If an error is returned from the callback, then iteration stops immediately. Any error returned from the callback is returned by PrioritySearch, except for the case where the special Stop sentinel error is returned (in which case nil will be returned from PrioritySearch). Stop may be wrapped.
func (*RTree) RangeSearch ¶ added in v0.17.0
RangeSearch looks for any items in the tree that overlap with the given bounding box. The callback is called with the record ID for each found item. If an error is returned from the callback then the search is terminated early. Any error returned from the callback is returned by RangeSearch, except for the case where the special Stop sentinel error is returned (in which case nil will be returned from RangeSearch). Stop may be wrapped.