Class RTree<T>

  • Type Parameters:
    T - Value type.
    All Implemented Interfaces:
    BoxMap<T>, BoxMultimap<T>, Index

    public class RTree<T>
    extends Object
    implements BoxMap<T>, BoxMultimap<T>
    R*Tree implementation based on the paper from Beckmann, N.; Kriegel, H. P.; Schneider, R.; Seeger, B. (1990). "The R*-tree: an efficient and robust access method for points and rectangles".

    Revised R*Tree (for DBMS, see conclusion?) -- RR*Tree "A Revised R*-tree in Comparison with Related Index Structures" Norbert Beckmann; Bernhard Seeger

    Author:
    ztilmann
    • Constructor Detail

      • RTree

        protected RTree​(int dims)
        Create an RTree. By default, it is an R*tree.
        Parameters:
        dims - dimensionality
    • Method Detail

      • createRStar

        public static <T> RTree<T> createRStar​(int dims)
      • getDims

        public int getDims()
        Specified by:
        getDims in interface Index
        Returns:
        the number of dimensions
      • size

        public int size()
        Specified by:
        size in interface Index
        Returns:
        the number of entries
      • clear

        public void clear()
        Description copied from interface: Index
        Clear all entries.
        Specified by:
        clear in interface Index
      • insert

        public void insert​(double[] point,
                           T value)
      • insert

        public void insert​(double[] keyMin,
                           double[] keyMax,
                           T value)
        Insert a rectangle.
        Specified by:
        insert in interface BoxMap<T>
        Specified by:
        insert in interface BoxMultimap<T>
        Parameters:
        keyMin - min
        keyMax - max
        value - value
      • insert

        public void insert​(RTreeEntry<T> e)
        Insert an entry.
        Parameters:
        e - the entry
      • remove

        public Object remove​(double[] point)
      • remove

        public T remove​(double[] min,
                        double[] max)
        Remove an entry.
        Specified by:
        remove in interface BoxMap<T>
        Parameters:
        min - min
        max - max
        Returns:
        the value of the entry or null if the entry was not found
      • remove

        public boolean remove​(double[] min,
                              double[] max,
                              T value)
        Remove an entry.
        Specified by:
        remove in interface BoxMultimap<T>
        Parameters:
        min - min
        max - max
        value - value
        Returns:
        the value of the entry or null if the entry was not found
      • removeIf

        public boolean removeIf​(double[] min,
                                double[] max,
                                Predicate<Index.BoxEntry<T>> condition)
        Remove the first entry matching the geometry and condition.
        Specified by:
        removeIf in interface BoxMultimap<T>
        Parameters:
        min - min
        max - max
        condition - Condition for deletion.
        Returns:
        `true` iff an entry was found and removed
      • update

        public T update​(double[] lo1,
                        double[] up1,
                        double[] lo2,
                        double[] up2)
        Update the position of an entry.
        Specified by:
        update in interface BoxMap<T>
        Parameters:
        lo1 - old min
        up1 - old max
        lo2 - new min
        up2 - new max
        Returns:
        the value, or null if the entries was not found
      • update

        public boolean update​(double[] lo1,
                              double[] up1,
                              double[] lo2,
                              double[] up2,
                              T value)
        Update the position of an entry.
        Specified by:
        update in interface BoxMultimap<T>
        Parameters:
        lo1 - old min
        up1 - old max
        lo2 - new min
        up2 - new max
        value - only entry with the given value is updated
        Returns:
        `true` iff the entry was found and relocated
      • contains

        public boolean contains​(double[] min,
                                double[] max)
        Description copied from interface: BoxMap
        Lookup an entry, using exact match.
        Specified by:
        contains in interface BoxMap<T>
        Parameters:
        min - minimum corner
        max - maximum corner
        Returns:
        `true` if an entry was found, otherwise `false`.
      • contains

        public boolean contains​(double[] min,
                                double[] max,
                                T value)
        Description copied from interface: BoxMultimap
        Lookup an entry, using exact match.
        Specified by:
        contains in interface BoxMultimap<T>
        Parameters:
        min - minimum corner
        max - maximum corner
        value - the value
        Returns:
        `true` if an entry was found, otherwise `false`.
      • queryExact

        public T queryExact​(double[] min,
                            double[] max)
        Description copied from interface: BoxMap
        Lookup an entry, using exact match.
        Specified by:
        queryExact in interface BoxMap<T>
        Parameters:
        min - minimum corner
        max - maximum corner
        Returns:
        the value of the entry or null if the entry was not found
      • queryExactBox

        public RTreeIterator<T> queryExactBox​(double[] min,
                                              double[] max)
        Description copied from interface: BoxMultimap
        Lookup an entry, using exact match.
        Specified by:
        queryExactBox in interface BoxMultimap<T>
        Parameters:
        min - minimum corner
        max - maximum corner
        Returns:
        an iterator over all entries with the exact given box shape
      • queryIntersect

        public RTreeIterator<T> queryIntersect​(double[] min,
                                               double[] max)
        Specified by:
        queryIntersect in interface BoxMap<T>
        Specified by:
        queryIntersect in interface BoxMultimap<T>
        Parameters:
        min - Lower left corner of the query window
        max - Upper right corner of the query window
        Returns:
        All boxes that intersect with the query rectangle.
      • query1nn

        public Index.BoxEntryKnn<T> query1nn​(double[] center)
        Description copied from interface: BoxMap
        Finds the nearest neighbor. This uses Euclidean 'edge distance'. Other distance types can only be specified directly on the index implementations.
        Specified by:
        query1nn in interface BoxMap<T>
        Specified by:
        query1nn in interface BoxMultimap<T>
        Parameters:
        center - center point
        Returns:
        the nearest neighbor
      • queryKnn

        public RTreeQueryKnn<T> queryKnn​(double[] center,
                                         int k)
        Description copied from interface: BoxMap
        Finds the nearest neighbor. This uses Euclidean 'edge distance', i.e. the distance to the edge of a box. Distance is 0 if the box overlaps with the search point. Other distance types can only be specified directly on the index implementations.
        Specified by:
        queryKnn in interface BoxMap<T>
        Specified by:
        queryKnn in interface BoxMultimap<T>
        Parameters:
        center - center point
        k - number of neighbors
        Returns:
        list of nearest neighbors
      • queryKnn

        public RTreeQueryKnn<T> queryKnn​(double[] center,
                                         int k,
                                         BoxDistance dist)
        Description copied from interface: BoxMultimap
        Finds the nearest neighbor. This uses a custom distance function for distances to boxes.
        Specified by:
        queryKnn in interface BoxMultimap<T>
        Parameters:
        center - center point
        k - number of neighbors
        dist - distance function
        Returns:
        list of nearest neighbors
      • queryRangedNearestNeighbor

        public Iterable<Index.BoxEntryKnn<T>> queryRangedNearestNeighbor​(double[] center,
                                                                         BoxDistance dist,
                                                                         BoxDistance closestDist,
                                                                         Filter filter)
        This method returns an Iterable which returns the nodes by a combined range and nearest number search. The Iterator supports the Iterator.remove() method.
        Parameters:
        center - Target position passed as parameter to the distance functions. Can be null if your distance function supports it (like RectangleDistanceFunction.RectangleDist).
        dist - Distance function used to compare entries (example: RectangleDistanceFunction.EDGE or RectangleDistanceFunction.CENTER)
        closestDist - Distance of the best point in a given rectangle (example: RectangleDistanceFunction.EDGE but *not* RectangleDistanceFunction.CENTER)
        filter - Filter to limit the results for range queries (example: new Filter.RectangleIntersectFilter(min, max))
        Returns:
        An Iterable which lazily calculates the nearest neighbors.
      • toStringTree

        public String toStringTree()
        Specified by:
        toStringTree in interface Index
        Returns:
        a full string output of the tree structure with all entries
      • getStats

        public RTree.RTreeStats getStats()
        Specified by:
        getStats in interface Index
        Returns:
        Collect and return some index statistics. Note that indexes are not required to fill all fields. Also, individual indexes may use subclasses with additional fields.
      • getDepth

        public int getDepth()
        Specified by:
        getDepth in interface Index
      • getNodeCount

        public int getNodeCount()
        Specified by:
        getNodeCount in interface Index
      • getRoot

        protected org.tinspin.index.rtree.RTreeNode<T> getRoot()