2

Problem

I have a location point = [(580991.4677, 4275267.6366, 192.2548)] I want to calculate the distance from point to the nearest location in X and insert it to the point. This means dist will be something like this: [(580991.4677, 4275267.6366, 192.2548, <distance value>)] The matching point is not important, but the distance value is.

Sample data: X

[(580991.4344, 4275267.6452, 192.3217),
 (580991.4369, 4275267.4457, 192.3945),
 (580991.4375, 4275267.4929, 192.396),
 (580991.4599, 4275267.5186, 192.3361),
 (580991.4644, 4275267.5889, 192.2631)]

Script

So far I can calculate the n-distances. But this is calculating the distances between the points in the array X, not in comparison to the point object.

import scipy.spatial.distance
dist = scipy.spatial.distance.pdist(X, metric='euclidean')

Result

array([0.21238253, 0.16948566, 0.12994295, 0.08662361, 0.04722764,
   0.09619756, 0.19628665, 0.06892213, 0.16613856, 0.10144624])

Any pointers?

Spatial Digger
  • 1,883
  • 1
  • 19
  • 37

1 Answers1

2

Well from the docs: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.pdist.html

scipy.spatial.distance.pdist calculates the distance between each pair of points in a single list.

If you want to calculate the distance between point and every entry in X, you probably want cdist which does the following:

Compute distance between each pair of the two collections of inputs.

so you would call: scipy.spatial.distance.cdist(point, X)

killian95
  • 803
  • 6
  • 11