protected void insert(Object bounds, Object item) { Assert.isTrue(!built, "Cannot insert items into an STR packed R-tree after it has been built."); itemBoundables.add(new ItemBoundable(bounds, item)); }
private List itemWrappers(int size) { ArrayList itemWrappers = new ArrayList(); for (int i = 0; i < size; i++) { itemWrappers.add(new ItemBoundable(new Envelope(0, 0, 0, 0), new Object())); } return itemWrappers; }
/** * Finds the item in this tree which is nearest to the given {@link Object}, * using {@link ItemDistance} as the distance metric. * A Branch-and-Bound tree traversal algorithm is used * to provide an efficient search. * <p> * The query <tt>object</tt> does <b>not</b> have to be * contained in the tree, but it does * have to be compatible with the <tt>itemDist</tt> * distance metric. * * @param env the envelope of the query item * @param item the item to find the nearest neighbour of * @param itemDist a distance metric applicable to the items in this tree and the query item * @return the nearest item in this tree */ public Object nearestNeighbour(Envelope env, Object item, ItemDistance itemDist) { Boundable bnd = new ItemBoundable(env, item); BoundablePair bp = new BoundablePair(this.getRoot(), bnd, itemDist); return nearestNeighbour(bp)[0]; }
/** * Finds k items in this tree which are the top k nearest neighbors to the given {@code item}, * using {@code itemDist} as the distance metric. * A Branch-and-Bound tree traversal algorithm is used * to provide an efficient search. * This method implements the KNN algorithm described in the following paper: * <p> * Roussopoulos, Nick, Stephen Kelley, and Frédéric Vincent. "Nearest neighbor queries." * ACM sigmod record. Vol. 24. No. 2. ACM, 1995. * <p> * The query {@code item} does <b>not</b> have to be * contained in the tree, but it does * have to be compatible with the {@code itemDist} * distance metric. * * @param env the envelope of the query item * @param item the item to find the nearest neighbour of * @param itemDist a distance metric applicable to the items in this tree and the query item * @param k the K nearest items in kNearestNeighbour * @return the K nearest items in this tree */ public Object[] nearestNeighbour(Envelope env, Object item, ItemDistance itemDist,int k) { Boundable bnd = new ItemBoundable(env, item); BoundablePair bp = new BoundablePair(this.getRoot(), bnd, itemDist); return nearestNeighbour(bp,k); } /**