Package org.tinspin.index.rtree
Class RTree<T>
- java.lang.Object
-
- org.tinspin.index.rtree.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRTree.RTreeStats-
Nested classes/interfaces inherited from interface org.tinspin.index.BoxMap
BoxMap.Factory
-
Nested classes/interfaces inherited from interface org.tinspin.index.BoxMultimap
BoxMultimap.Factory
-
Nested classes/interfaces inherited from interface org.tinspin.index.Index
Index.BEComparator, Index.BoxEntry<T>, Index.BoxEntryKnn<T>, Index.BoxFilterKnn<T>, Index.BoxIterator<T>, Index.BoxIteratorKnn<T>, Index.PEComparator, Index.PointEntry<T>, Index.PointEntryKnn<T>, Index.PointFilterKnn<T>, Index.PointIterator<T>, Index.PointIteratorKnn<T>, Index.QueryIterator<T>, Index.QueryIteratorKnn<T>
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEBUG
-
Constructor Summary
Constructors Modifier Constructor Description protectedRTree(int dims)Create an RTree.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear all entries.booleancontains(double[] min, double[] max)Lookup an entry, using exact match.booleancontains(double[] min, double[] max, T value)Lookup an entry, using exact match.static <T> RTree<T>createRStar(int dims)intgetDepth()intgetDims()intgetNodeCount()protected org.tinspin.index.rtree.RTreeNode<T>getRoot()RTree.RTreeStatsgetStats()voidinsert(double[] keyMin, double[] keyMax, T value)Insert a rectangle.voidinsert(double[] point, T value)voidinsert(RTreeEntry<T> e)Insert an entry.RTreeIterator<T>iterator()voidload(RTreeEntry<T>[] entries)Index.BoxEntryKnn<T>query1nn(double[] center)Finds the nearest neighbor.TqueryExact(double[] min, double[] max)Lookup an entry, using exact match.RTreeIterator<T>queryExactBox(double[] min, double[] max)Lookup an entry, using exact match.RTreeIterator<T>queryIntersect(double[] min, double[] max)RTreeQueryKnn<T>queryKnn(double[] center, int k)Finds the nearest neighbor.RTreeQueryKnn<T>queryKnn(double[] center, int k, BoxDistance dist)Finds the nearest neighbor.Iterable<Index.BoxEntryKnn<T>>queryRangedNearestNeighbor(double[] center, BoxDistance dist, BoxDistance closestDist, double[] minBound, double[] maxBound)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.Objectremove(double[] point)Tremove(double[] min, double[] max)Remove an entry.booleanremove(double[] min, double[] max, T value)Remove an entry.booleanremoveIf(double[] min, double[] max, Predicate<Index.BoxEntry<T>> condition)Remove the first entry matching the geometry and condition.intsize()StringtoString()StringtoStringTree()Tupdate(double[] lo1, double[] up1, double[] lo2, double[] up2)Update the position of an entry.booleanupdate(double[] lo1, double[] up1, double[] lo2, double[] up2, T value)Update the position of an entry.
-
-
-
Field Detail
-
DEBUG
public static final boolean DEBUG
- See Also:
- Constant Field Values
-
-
Method Detail
-
createRStar
public static <T> RTree<T> createRStar(int dims)
-
getDims
public int getDims()
-
clear
public void clear()
Description copied from interface:IndexClear all entries.
-
insert
public void insert(double[] point, T value)
-
insert
public void insert(double[] keyMin, double[] keyMax, T value)Insert a rectangle.
-
insert
public void insert(RTreeEntry<T> e)
Insert an entry.- Parameters:
e- the entry
-
load
public void load(RTreeEntry<T>[] entries)
-
remove
public Object remove(double[] point)
-
remove
public T remove(double[] min, double[] max)
Remove an entry.
-
remove
public boolean remove(double[] min, double[] max, T value)Remove an entry.- Specified by:
removein interfaceBoxMultimap<T>- Parameters:
min- minmax- maxvalue- 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:
removeIfin interfaceBoxMultimap<T>- Parameters:
min- minmax- maxcondition- 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.
-
update
public boolean update(double[] lo1, double[] up1, double[] lo2, double[] up2, T value)Update the position of an entry.- Specified by:
updatein interfaceBoxMultimap<T>- Parameters:
lo1- old minup1- old maxlo2- new minup2- new maxvalue- 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:BoxMapLookup an entry, using exact match.
-
contains
public boolean contains(double[] min, double[] max, T value)Description copied from interface:BoxMultimapLookup an entry, using exact match.- Specified by:
containsin interfaceBoxMultimap<T>- Parameters:
min- minimum cornermax- maximum cornervalue- the value- Returns:
- `true` if an entry was found, otherwise `false`.
-
queryExact
public T queryExact(double[] min, double[] max)
Description copied from interface:BoxMapLookup an entry, using exact match.- Specified by:
queryExactin interfaceBoxMap<T>- Parameters:
min- minimum cornermax- maximum corner- Returns:
- the value of the entry or null if the entry was not found
-
iterator
public RTreeIterator<T> iterator()
-
queryExactBox
public RTreeIterator<T> queryExactBox(double[] min, double[] max)
Description copied from interface:BoxMultimapLookup an entry, using exact match.- Specified by:
queryExactBoxin interfaceBoxMultimap<T>- Parameters:
min- minimum cornermax- 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:
queryIntersectin interfaceBoxMap<T>- Specified by:
queryIntersectin interfaceBoxMultimap<T>- Parameters:
min- Lower left corner of the query windowmax- 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:BoxMapFinds the nearest neighbor. This uses Euclidean 'edge distance'. Other distance types can only be specified directly on the index implementations.
-
queryKnn
public RTreeQueryKnn<T> queryKnn(double[] center, int k)
Description copied from interface:BoxMapFinds 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.
-
queryKnn
public RTreeQueryKnn<T> queryKnn(double[] center, int k, BoxDistance dist)
Description copied from interface:BoxMultimapFinds the nearest neighbor. This uses a custom distance function for distances to boxes.- Specified by:
queryKnnin interfaceBoxMultimap<T>- Parameters:
center- center pointk- number of neighborsdist- distance function- Returns:
- list of nearest neighbors
-
queryRangedNearestNeighbor
public Iterable<Index.BoxEntryKnn<T>> queryRangedNearestNeighbor(double[] center, BoxDistance dist, BoxDistance closestDist, double[] minBound, double[] maxBound)
-
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 theIterator.remove()method.- Parameters:
center- Target position passed as parameter to the distance functions. Can benullif your distance function supports it (likeRectangleDistanceFunction.RectangleDist).dist- Distance function used to compare entries (example:RectangleDistanceFunction.EDGEorRectangleDistanceFunction.CENTER)closestDist- Distance of the best point in a given rectangle (example:RectangleDistanceFunction.EDGEbut *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:
toStringTreein interfaceIndex- Returns:
- a full string output of the tree structure with all entries
-
getStats
public RTree.RTreeStats getStats()
-
getNodeCount
public int getNodeCount()
- Specified by:
getNodeCountin interfaceIndex
-
getRoot
protected org.tinspin.index.rtree.RTreeNode<T> getRoot()
-
-