Change the nearest neighbor reseach from NearestNeighbor to KDTree