nearestNeighbourWithEnv method

List<Object> nearestNeighbourWithEnv(
  1. Envelope env,
  2. Object item,
  3. ItemDistance itemDist,
  4. int k,
)

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:

Roussopoulos, Nick, Stephen Kelley, and Frédéric Vincent. "Nearest neighbor queries." ACM sigmod record. Vol. 24. No. 2. ACM, 1995.

The query {@code item} does not 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

Implementation

List<Object> nearestNeighbourWithEnv(
    Envelope env, Object item, ItemDistance itemDist, int k) {
  Boundable bnd = new ItemBoundable(env, item);
  BoundablePair bp = new BoundablePair(this.getRoot(), bnd, itemDist);
  return nearestNeighbourK(bp, k);
}