Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Provided the list of points remains sufficiently small, a linear search should do the trick:</p> <pre><code>def dist_sq(a, b): # distance squared (don't need the square root) return (a[0] - b[0])**2 + (a[1] - b[1])**2 def find(l, coord): return min(l, key=lambda p:dist_sq(coord, p)) l = [(35.9879845760485, -4.74093235801354), (35.9888687992442, -4.72708076713794), (35.9889733432982, -4.72758983150694), (35.9915751019521, -4.72772881198689), (35.9935223025608, -4.72814213543564), (35.9941433944962, -4.72867416528065), (35.9946670576458, -4.72915181755908), (35.995946587966, -4.73005565674077), (35.9961479762973, -4.7306870912609), (35.9963563641681, -4.7313535758683), (35.9968685892892, -4.73182757975504), (35.9976738530666, -4.73194429867996) ] coord = (35.9945570576458, -4.73110757975504) print find(l, coord) </code></pre> <p>The same solution using <code>numpy</code>:</p> <pre><code>import numpy as np l = np.array([(35.9879845760485, -4.74093235801354), (35.9888687992442, -4.72708076713794), (35.9889733432982, -4.72758983150694), (35.9915751019521, -4.72772881198689), (35.9935223025608, -4.72814213543564), (35.9941433944962, -4.72867416528065), (35.9946670576458, -4.72915181755908), (35.995946587966, -4.73005565674077), (35.9961479762973, -4.7306870912609), (35.9963563641681, -4.7313535758683), (35.9968685892892, -4.73182757975504), (35.9976738530666, -4.73194429867996) ]) coord = np.array((35.9945570576458, -4.73110757975504)) print l[np.argmin(np.apply_along_axis(np.linalg.norm, 1, l - coord))] </code></pre> <p>If that's not feasible, I suggest you look into <a href="http://en.wikipedia.org/wiki/Nearest_neighbor_search#Methods" rel="nofollow">better algorithmic approaches</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload