RTree
A high-performance R-tree-based spatial index for 2D points and rectangles.
RTree is an implementation of an R-tree, a tree data structure used for spatial access methods, i.e., for indexing multi-dimensional information such as geographical coordinates, rectangles, or polygons. It's a popular choice for spatial indexing due to its efficiency in handling dynamic datasets (i.e., data that changes over time) and its speed in performing spatial queries.
This implementation is a port of the JavaScript RBush library and is optimized for indexing and querying large datasets of geographical features. It supports operations like insertion, removal, and spatial searches (e.g., finding all items within a given bounding box).
The performance of the R-tree is heavily influenced by the maxEntries parameter. A higher value for maxEntries leads to a tree with fewer, fuller nodes. This can speed up initial loading and insertion operations but may slow down search queries because each node covers a larger area. Conversely, a lower maxEntries value creates a more fine-grained tree with smaller nodes, which can be faster for searches but slower for insertions. The default value of 16 is a commonly used and well-balanced choice.
Parameters
The type of Feature to be stored in the tree. The feature's geometry is used to calculate its bounding box for indexing.
The maximum number of entries in a single tree node. A higher value leads to faster loading/insertion but slower searches, and vice versa. Must be 4 or greater. Defaults to 16.
Constructors
Functions
Checks if there are any items in the tree that intersect with the given bounding box. This is a faster alternative to search if you only need to know if an intersection exists, as it returns as soon as the first overlapping item is found.
Finds the nearest point in the collection to the given position.
Searches the R-tree for all items that intersect with the given bounding box.