0

Pandas beginner here. I have a set of coordinates of ships positions and a set of coordinates of segments that make up the ship route. I would like to know which point on the route is the closest to the ship. I then use that point to calculate the total distance from the ship location to the next point and the next till the end of the set. There is a similar question but they are slightly different problems: similar questions here and here.

SHIP LAT    SHIP LNG
40.77110    14.0301
40.77110    14.0501

ROUTE 1 LAT   ROUTE 1 LNG
40.74556      13.93871
40.74477      13.94019
40.75093      13.94584
40.76589      13.99974
40.77114      14.01122
40.77109      14.0301
40.76585      14.02673

I have achieved what I want with without using panda and struggling it to apply to a dataframe.

for segment in segments:
        proximity = min(haversine(lng,lat, point[0], point[1]) for point in segment)
        print('proximity point')
        print(proximity)
        for point in segment:
            if haversine(lng,lat, point[0], point[1]) == proximity:
                closest_point = point
            point_index = segment.index(point)
        print('closest point')
        print(point_index)
        total_distance = proximity
        i = point_index
        last_index = len(segment)-1
        while i < last_index:
            seg_distance =  haversine(segment[i][0], segment[i][1], segment[i+1][0], segment[i+1][1])
            print('segment distance')
            print(seg_distance)
            total_distance += seg_distance
            i += 1
Daniela
  • 861
  • 5
  • 11
  • 28
  • Your first link is about finding the distances between a single point and a series of points. This is analogous to finding the distance between your first ship's position and the series of route positions, then doing it again for the next ship's position. So you could apply that question's solution to each ship position (in turn). – wwii Oct 18 '19 at 15:34
  • Good idea I didn't think about it. I'll give it a go. Thank you @wwii – Daniela Oct 18 '19 at 16:25

0 Answers0