Search code examples
pythonnumpyscipykdtree

KDTree double type integers


I have a list of 2 dimensional coordinates that I am creating a kdtree from. The coordinates are of type double- e.g. [508180.748, 195333.973]

I use numpy to create and array and I then use scipy's KDTree functions.

import numpy as np
import scipy.spatial

points_array = np.array(points)
kdt = scipy.spatial.KDTree(points_array)

# Query    
tester = kdt.query_pairs(20)
tester = list(tester)    
print(tester[0])

This returns:

(109139, 109144)

The result has lost the resolution of the original data. How do I keep the double precision floating point format?


Solution

  • These are the indices in the array of points, not coordinate values of the points themselves. The tuple has two indices, one for each point in the array that is part of a pair whose separation in your coordinate space is less than the query distance.

    To see the values of the coordinates of the points in your pair, you could do the following:

    tester = kdt.query_pairs(20)
    tester = list(tester)    
    print(points_array[tester[0][0]], points_array[tester[0][1]])