redefine the constructor to be more flexible with constraints, etc.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import numpy as np
|
||||
import pyproj
|
||||
import sys
|
||||
|
||||
class Waypoint:
|
||||
def dms2dd(coordinate : str):
|
||||
@@ -20,9 +21,44 @@ class Waypoint:
|
||||
|
||||
return dd
|
||||
|
||||
def __init__(self, name : str, latitude : float, longitude : float):
|
||||
self.Name = name
|
||||
self.Coordinate = np.array([ latitude, longitude ])
|
||||
def coordinateArgument(value):
|
||||
if True == isinstance(value, str):
|
||||
return Waypoint.dms2dd(value)
|
||||
elif True == isinstance(value, (float, int)):
|
||||
return float(value)
|
||||
else:
|
||||
raise Exception('Invalid constructor argument')
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.Name = None
|
||||
self.Coordinate = None
|
||||
self.Altitude = None
|
||||
self.Speed = None
|
||||
self.BaseTurn = False
|
||||
self.FinalTurn = False
|
||||
|
||||
latitude = None
|
||||
longitude = None
|
||||
for key, value in kwargs.items():
|
||||
if 'name' == key.lower():
|
||||
self.Name = str(value)
|
||||
elif 'latitude' == key.lower():
|
||||
latitude = Waypoint.coordinateArgument(value)
|
||||
elif 'longitude' == key.lower():
|
||||
longitude = Waypoint.coordinateArgument(value)
|
||||
elif 'altitude' == key.lower():
|
||||
self.Altitude = int(value)
|
||||
elif 'speed' == key.lower():
|
||||
self.Speed = int(value)
|
||||
elif 'base' == key:
|
||||
self.BaseTurn = bool(value)
|
||||
elif 'final' == key:
|
||||
self.FinalTurn = bool(value)
|
||||
else:
|
||||
raise Exception('Invalid constructor argument: ' + key)
|
||||
|
||||
if None != latitude and None != longitude:
|
||||
self.Coordinate = np.array([ latitude, longitude ])
|
||||
|
||||
def __str__(self):
|
||||
return 'Name: ' + self.Name + ', Lat: ' + str(self.Coordinate[0]) + ', Lon: ' + str(self.Coordinate[1])
|
||||
|
||||
Reference in New Issue
Block a user