0

I have 2 lists composed of 100's of GPS coordinates each.

For each element is list1, I want to find the element in list2 it is closest to. To do this, I want to use havesine and python.

from haversine import haversine
list1=[45.7, 4.8,45.6,4.8]
list2=[48.8, 2.3,48.8,2.4]
haversine(list1[0:2],list2[0:2])

I was thinking of looping through it twice, first through list1, and then again through list2, to compare every single point. I think that is too hard and slow. Is there a way to compute this faster.

A look around SO, I found Haversine Formula in Python (Bearing and Distance between two GPS points), but it does not address many to many comparisons

frank
  • 3,036
  • 7
  • 33
  • 65
  • 1
    "I think that is too hard and slow." Did you test it? 100 x 100 is pretty tiny when calling a general Haversine function. It's manageable to even get real-road distances between locations at that scale – roganjosh Jun 27 '19 at 13:57
  • My real data is 3k by 7k. I set it up and it is still running (~20min), so trying to get some ideas to speed it up. – frank Jun 27 '19 at 14:01
  • Why do you need every distance pair? What is it you're trying to do? – roganjosh Jun 27 '19 at 14:02
  • I want to find the closest point to it – frank Jun 27 '19 at 14:08
  • @alex It would be faster if you only loop through `list1`, and feed `list2` as an array into `haversine` function. The return of the `haversine` function will be an array of all the distances between a point in `list1` and all the points in `list2`, so you can find the minimum one among them. – GeoMSI Jun 27 '19 at 19:21

0 Answers0