def get_midpoint(lat1, long1, lat2, long2): try: lat1 = float(lat1) long1 = float(long1) lat2 = float(lat2) long2 = float(long2) azimuth = get_bearing(lat1, long1, lat2, long2) distance = get_distance(lat1, long1, lat2, long2) / 2 coords = get_point(lat1, long1, azimuth, distance) return coords except Exception as e: return 'Exception:' + e
def main(): try: if len(sys.argv) > 1: arg = sys.argv[1] if arg == 1: log('Nautical Distance') result = get_distance(float(sys.argv[2]), float(sys.argv[3]), float(sys.argv[4]), float(sys.argv[5])) print('Nautical Distance (km): ', result) elif arg == 2: log('bearing') result = get_bearing(float(sys.argv[2]), float(sys.argv[3]), float(sys.argv[4]), float(sys.argv[5])) print('Bearing: ', result) elif arg == 3: log('get_point') result = get_point(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]) print('Resultant point: ', result) elif arg == 4: log('divide_by_number') result = divide_by_number(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6]) print('Resultant points:', result) elif arg == 5: log('divide_by_interval') result = divide_by_interval(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6]) print('Resultant points: ', result) elif arg == 6: log('Midpoint') result = get_midpoint(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]) print('Resultant point: ', result) elif arg == 7: log('Rhumb Line') result = rhumb_line(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]) print('Resultant point: ', result) else: print('Welcome to nautical_calculations') except Exception as e: print(e)
def divide_by_interval(lat1, long1, lat2, long2, interval): try: lat1 = float(lat1) long1 = float(long1) lat2 = float(lat2) long2 = float(long2) coordinate_list = [] azimuth = get_bearing(lat1, long1, lat2, long2) d = get_distance(lat1, long1, lat2, long2) remainder, dist = modf((d / interval)) counter = float(interval) coordinate_list.append([lat1, long1]) for distance in range(0, int(dist)): coord = get_point(lat1, long1, azimuth, counter) counter = counter + float(interval) coordinate_list.append(coord) coordinate_list.append([lat2, long2]) return coordinate_list except Exception as e: return 'Exception: ' + e
def divide_by_number(lat1, long1, lat2, long2, num): try: lat1 = float(lat1) long1 = float(long1) lat2 = float(lat2) long2 = float(long2) num = num + 1 coordinate_list = [] azimuth = get_bearing(lat1, long1, lat2, long2) dist = get_distance(lat1, long1, lat2, long2) dist = (dist / num) counter = float(dist) coordinate_list.append([lat1, long1]) for distance in range(num - 1): coord = get_point(lat1, long1, azimuth, counter) counter = counter + float(dist) coordinate_list.append(coord) coordinate_list.append([lat2, long2]) return coordinate_list except Exception as e: return 'Exception: ' + e
def main(): try: while (True): print( "Enter choice:\n1.Calculate distance\n2.Calculate bearing\n3.Get Point\n4.Divide by number\n5.Divide by interval\n6.Midpoint\n7.Calculate Rhumb-line distance" ) ch = str(input()) if (ch == '1'): print('Enter coordinates of first point (lat1, long1)') lat1 = input() long1 = input() print('Enter coordinates of second point (lat2, long2)') lat2 = input() long2 = input() distance = get_distance(lat1, long1, lat2, long2) print('Nautical distance: ', distance) elif (ch == '2'): print('Enter coordinates of first point (lat1, long1)') lat1 = input() long1 = input() print('Enter coordinates of second point (lat2, long2)') lat2 = input() long2 = input() bearing = get_bearing(lat1, long1, lat2, long2) print('Bearing (degress): ', bearing) elif (ch == '3'): print('Enter coordinates of start point (lat, long)') lat = input() long = input() print('Enter Azimuth (angle) in degrees') azimuth = input() print('Enter distance in nautical_kms') distance = input() point = get_point(lat, long, azimuth, distance) print('Resultant point: ', point) elif (ch == '4'): print('Enter coordinates of first point (lat1, long1)') lat1 = input() long1 = input() print('Enter coordinates of second point (lat2, long2)') lat2 = input() long2 = input() print('Enter number of intermidiate points') num = input() list = divide_by_number(lat1, long1, lat2, long2, num) print('List: \n', list) elif (ch == '5'): print('Enter coordinates of first point (lat1, long1)') lat1 = input() long1 = input() print('Enter coordinates of second point (lat2, long2)') lat2 = input() long2 = input() print('Enter the value of interval') interval = input() list = divide_by_interval(lat1, long1, lat2, long2, interval) print('List: \n', list) elif (ch == '6'): print('Enter coordinates of first point (lat1, long1)') lat1 = input() long1 = input() print('Enter coordinates of second point (lat2, long2)') lat2 = input() long2 = input() coords = get_midpoint(lat1, long1, lat2, long2) print('Midpoint: \n', coords) elif (ch == '7'): print('Enter coordinates of first point (lat1, long1)') lat1 = input() long1 = input() print('Enter coordinates of second point (lat2, long2)') lat2 = input() long2 = input() distance = rhumb_line(lat1, long1, lat2, long2) print('Rhumb Line distance: ', distance) else: print('Invalid command, retry') continue print('continue? (1/0)') ch = str(input()) if (ch == '0'): break except Exception as e: print(e)