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:
Index<T>,RectangleIndex<T>,RectangleIndexMM<T>
public class RTree<T> extends Object implements RectangleIndex<T>, RectangleIndexMM<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 Interesting comparison: http://www.boost.org/doc/libs/1_58_0/libs/geometry/doc/html/geometry/spatial_indexes/introduction.html- Author:
- ztilmann
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRTree.RTreeStats
-
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, 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(Entry<T> e)Insert an entry.RTreeIterator<T>iterator()voidload(Entry<T>[] entries)RectangleEntryDist<T>query1NN(double[] center)Finds the nearest neighbor.TqueryExact(double[] min, double[] max)Lookup an entry, using exact match.RTreeIterator<T>queryIntersect(double[] min, double[] max)RTreeQueryKnn2<T>queryKNN(double[] center, int k)Finds the nearest neighbor.RTreeQueryKnn2<T>queryKNN(double[] center, int k, RectangleDistanceFunction dist)Finds the nearest neighbor.Iterable<RectangleEntryDist<T>>queryRangedNearestNeighbor(double[] center, RectangleDistanceFunction dist, RectangleDistanceFunction closestDist, double[] minBound, double[] maxBound)Iterable<RectangleEntryDist<T>>queryRangedNearestNeighbor(double[] center, RectangleDistanceFunction dist, RectangleDistanceFunction closestDist, Filter filter)This method returns an Iterable which returns the nodes by a combined range and nearest number search.RTreeIterator<T>queryRectangle(double[] min, double[] max)Lookup an entry, using exact match.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<RectangleEntry<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.- Specified by:
insertin interfaceRectangleIndex<T>- Specified by:
insertin interfaceRectangleIndexMM<T>- Parameters:
keyMin- minkeyMax- maxvalue- value
-
remove
public Object remove(double[] point)
-
remove
public T remove(double[] min, double[] max)
Remove an entry.- Specified by:
removein interfaceRectangleIndex<T>- Parameters:
min- minmax- 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:
removein interfaceRectangleIndexMM<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<RectangleEntry<T>> condition)Remove the first entry matching the geometry and condition.- Specified by:
removeIfin interfaceRectangleIndexMM<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.- Specified by:
updatein interfaceRectangleIndex<T>- Parameters:
lo1- old minup1- old maxlo2- new minup2- 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:
updatein interfaceRectangleIndexMM<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, T value)Description copied from interface:RectangleIndexMMLookup an entry, using exact match.- Specified by:
containsin interfaceRectangleIndexMM<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:RectangleIndexLookup an entry, using exact match.- Specified by:
queryExactin interfaceRectangleIndex<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()
- Specified by:
iteratorin interfaceRectangleIndex<T>- Specified by:
iteratorin interfaceRectangleIndexMM<T>- Returns:
- An iterator over all entries.
-
queryRectangle
public RTreeIterator<T> queryRectangle(double[] min, double[] max)
Description copied from interface:RectangleIndexMMLookup an entry, using exact match.- Specified by:
queryRectanglein interfaceRectangleIndexMM<T>- Parameters:
min- minimum cornermax- maximum corner- Returns:
- an iterator over all entries at with the exact given rectangle
-
queryIntersect
public RTreeIterator<T> queryIntersect(double[] min, double[] max)
- Specified by:
queryIntersectin interfaceRectangleIndex<T>- Specified by:
queryIntersectin interfaceRectangleIndexMM<T>- Parameters:
min- Lower left corner of the query windowmax- Upper right corner of the query window- Returns:
- All rectangles that intersect with the query rectangle.
-
query1NN
public RectangleEntryDist<T> query1NN(double[] center)
Description copied from interface:RectangleIndexFinds the nearest neighbor. This uses euclidean 'edge distance'. Other distance types can only be specified directly on the index implementations.- Specified by:
query1NNin interfaceRectangleIndex<T>- Specified by:
query1NNin interfaceRectangleIndexMM<T>- Parameters:
center- center point- Returns:
- the nearest neighbor
-
queryKNN
public RTreeQueryKnn2<T> queryKNN(double[] center, int k)
Description copied from interface:RectangleIndexFinds the nearest neighbor. This uses euclidean 'edge distance', i.e. the distance to the edge of rectangle. Distance is 0 is the rectangle overlaps with the search point. Other distance types can only be specified directly on the index implementations.- Specified by:
queryKNNin interfaceRectangleIndex<T>- Specified by:
queryKNNin interfaceRectangleIndexMM<T>- Parameters:
center- center pointk- number of neighbors- Returns:
- list of nearest neighbors
-
queryKNN
public RTreeQueryKnn2<T> queryKNN(double[] center, int k, RectangleDistanceFunction dist)
Description copied from interface:RectangleIndexMMFinds the nearest neighbor. This uses a custom distance function for distances to rectangles.- Specified by:
queryKNNin interfaceRectangleIndexMM<T>- Parameters:
center- center pointk- number of neighborsdist- distance function- Returns:
- list of nearest neighbors
-
queryRangedNearestNeighbor
public Iterable<RectangleEntryDist<T>> queryRangedNearestNeighbor(double[] center, RectangleDistanceFunction dist, RectangleDistanceFunction closestDist, double[] minBound, double[] maxBound)
-
queryRangedNearestNeighbor
public Iterable<RectangleEntryDist<T>> queryRangedNearestNeighbor(double[] center, RectangleDistanceFunction dist, RectangleDistanceFunction 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<T>- 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<T>
-
getRoot
protected org.tinspin.index.rtree.RTreeNode<T> getRoot()
-
-