Class RTree<T>

java.lang.Object
org.oscim.utils.RTree<T>
All Implemented Interfaces:
Iterable<T>, SpatialIndex<T>

public class RTree<T> extends Object implements SpatialIndex<T>, Iterable<T>
Implementation of RTree, a multidimensional bounding rectangle tree.
  • Field Details

    • mRoot

      protected org.oscim.utils.RTree.Node mRoot
      Root of tree
    • nodesAlloc

      public int nodesAlloc
    • nodesFree

      public int nodesFree
  • Constructor Details

    • RTree

      public RTree()
  • Method Details

    • insert

      public void insert(double[] min, double[] max, T item)
      Insert item.
      Parameters:
      min - Min of bounding rect
      max - Max of bounding rect
      item - data.
    • insert

      public void insert(Box box, T item)
      Specified by:
      insert in interface SpatialIndex<T>
    • remove

      public boolean remove(double[] min, double[] max, T item)
      Remove item.
      Parameters:
      min - Min of bounding rect
      max - Max of bounding rect
      item - data.
    • remove

      public boolean remove(Box box, T item)
      Specified by:
      remove in interface SpatialIndex<T>
    • search

      public boolean search(double[] min, double[] max, SpatialIndex.SearchCb<T> cb, Object context)
      Find all items within search rectangle.
      Parameters:
      a_min - Min of search bounding rect
      a_max - Max of search bounding rect
      a_searchResult - Search result array. Caller should set grow size. Function will reset, not append to array.
      a_resultCallback - Callback function to return result. Callback should return 'true' to continue searching
      a_context - User context to pass as parameter to a_resultCallback
      Returns:
      Returns the number of entries found
    • search

      public boolean search(Box bbox, SpatialIndex.SearchCb<T> cb, Object context)
      Specified by:
      search in interface SpatialIndex<T>
    • search

      public List<T> search(Box bbox, List<T> results)
      Specified by:
      search in interface SpatialIndex<T>
    • searchKNearestNeighbors

      public List<T> searchKNearestNeighbors(Point center, int k, double maxDistance, List<T> results)
      See https://github.com/mourner/rbush-knn/blob/master/index.js
      Specified by:
      searchKNearestNeighbors in interface SpatialIndex<T>
    • searchKNearestNeighbors

      public void searchKNearestNeighbors(Point center, int k, double maxDistance, SpatialIndex.SearchCb<T> cb, Object context)
      Specified by:
      searchKNearestNeighbors in interface SpatialIndex<T>
    • size

      public int size()
      Count the data elements in this container. This is slow as no internal counter is maintained.
      Specified by:
      size in interface SpatialIndex<T>
    • clear

      public void clear()
      Remove all entries from tree.
      Specified by:
      clear in interface SpatialIndex<T>
    • printStats

      public void printStats()
    • insertRect

      public boolean insertRect(org.oscim.utils.RTree.Rect rect, T item, int level)
      Insert a data rectangle into an index structure. InsertRect provides for splitting the root; returns 1 if root was split, 0 if it was not. The level argument specifies the number of steps up from the leaf level to insert; e.g. a data rectangle goes in at level = 0. InsertRect2 does the recursion.
    • removeRect

      public boolean removeRect(org.oscim.utils.RTree.Rect rect, T item)
      Delete a data rectangle from an index structure. Pass in a pointer to a Rect, the tid of the record, ptr to ptr to root node.
      Returns:
      false if record not found, true if success. RemoveRect provides for eliminating the root.
    • searchStack

      public void searchStack(org.oscim.utils.RTree.Rect rect, SpatialIndex.SearchCb<T> cb, Object context)
    • searchStack

      public boolean searchStack(org.oscim.utils.RTree.Rect rect, List<T> results)
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>