Exemple #1
0
def question3():
    from waypoints import Waypoints
    numsteps = 10
    u = np.linspace(0, 1.0, numsteps)
    x = x_func(u)
    y = y_func(u)
    waypoints = Waypoints()
    waypoints.points = np.hstack(
        [x.reshape((len(x), 1)),
         y.reshape((len(y), 1))])
    solver = BSplineInterpolationSolver()
    curve = solver.solve(waypoints)
    plot_waypoints(waypoints)
    #plot_control_points(curve)
    xinterp, yinterp = interpolate.splev(np.linspace(
        0.0, 1.0, 10000), (curve.knot_vector, curve.control_points.T, 3))

    numsteps = 10000
    u = np.linspace(0, 1.0, numsteps)
    x = x_func(u)
    y = y_func(u)
    plt.plot(x, y, '-', label='original line')
    plt.plot(xinterp, yinterp, linestyle='-', label='b-spline interpolation')
    plt.grid()
    plt.axis('equal')
    plt.legend()
    plt.show()
Exemple #2
0
class Coords:
    def __init__(self, api_key):
        self._api_key = api_key
        self._waypoints = Waypoints()
        self._waypoints.parse_waypoints()

    def fetch_coords(self):
        gmaps = googlemaps.Client(key=self._api_key)

        fields = self._waypoints.fields
        points = self._waypoints.waypoints
        i = 0

        for point in points:
            dest = gmaps.geocode(point[fields.index('Search')])

            points[i][fields.index('Lon')] = str(
                dest[0]['geometry']['location']['lng'])
            points[i][fields.index('Lat')] = str(
                dest[0]['geometry']['location']['lat'])

            user_comment = ''
            if points[i][fields.index('Comment')] != '':
                user_comment = f' [{points[i][fields.index("Comment")]}]'
            points[i][fields.index(
                'Comment')] = f'{dest[0]["formatted_address"]}{user_comment}'

            print(
                f'{str(i + 1).rjust(4)}. Fetched {point[fields.index("Search")]} @ {points[i][fields.index("Lat")]}, {points[i][fields.index("Lon")]}'
            )

            i += 1

        self._waypoints.waypoints = points

    def generate_csv_with_coords(self, name='waypoints'):
        with open(f'output/{name}.csv', 'w') as f:
            writer = csv.writer(f)
            writer.writerow(self._waypoints.garmin_poi_fields)

            fields = self._waypoints.fields
            points = self._waypoints.waypoints
            i = 0

            for row in points:
                out = [
                    row[fields.index('Lon')], row[fields.index('Lat')],
                    row[fields.index('Name')], row[fields.index('Comment')]
                ]
                writer.writerow(out)

                i += 1
Exemple #3
0
 def test_find_by_name(self):
     waypoints = Waypoints()
     self.assertEqual("Knievel's Jump",
                      waypoints.info("KNJ Knievel's Jump")['name'])
     self.assertIsNone(waypoints.info("No such POI"))
Exemple #4
0
 def test_remaining_distance(self):
     waypoints = Waypoints("waypoints_test.json")
     self.assertEqual(4619.22936857578, waypoints.remaining_distance('BT'))
     self.assertEqual(856.5790562622092,
                      waypoints.remaining_distance('KNJ'))
     self.assertIsNone(waypoints.remaining_distance('No POI'))
Exemple #5
0
 def test_total_distance(self):
     waypoints = Waypoints("waypoints_test.json")
     self.assertEqual(4619.22936857578, waypoints.total_distance())
Exemple #6
0
 def test_adding_srv_crash(self):
     waypoints = Waypoints()
     num_waypoints = len(waypoints.names())
     waypoints.update_crash_location((12, 56))
     self.assertEqual(num_waypoints + 1, len(waypoints.names()))
Exemple #7
0
 def test_lists_waypoints(self):
     waypoints = Waypoints()
     self.assertTrue(len(waypoints.names()) > 5)
Exemple #8
0
 def test_latlon(self):
     waypoints = Waypoints("waypoints_test.json")
     self.assertEqual((-50.1221, -70.0577), waypoints.latlon("KNJ"))
     self.assertIsNone(waypoints.latlon("Not an id"))
Exemple #9
0
 def SetMonitor(self,waypoint):
     Waypoints.SetMonitor(self,waypoint)
Exemple #10
0
 def GetMonitor(self):
     mon = Waypoints.GetMonitor(self)
     if mon is not None:
         name,tolerance = mon
         return self.waypoints[name]
Exemple #11
0
 def __init__(self,registry):
     Log("simwpt","SimWaypoints::__init__()")
     self.waypoints = OpenDbmFile("waypoints","c")
     Waypoints.__init__(self,registry)
Exemple #12
0
def plugin_start3(plugin_dir):
    plugin_name = os.path.basename(os.path.dirname(__file__))
    logger = logging.getLogger(f'{appname}.{plugin_name}')
    this.route = Waypoints(plugin_dir, logger)
    return plugin_name
Exemple #13
0
 def __init__(self, api_key):
     self._api_key = api_key
     self._waypoints = Waypoints()
     self._waypoints.parse_waypoints()
Exemple #14
0
this._rate = rate.Rate()
this._location = None  # Normally the last known lat lon in a tuple

#this.debug = True if platform == 'darwin' else False
this.NO_VALUE = "---"  # Used when we don't have a value for a field
this.debug_buttons = False  # Set True to display buttons for debugging

window = tk.Tk()
window.withdraw()


def local_file(name):
    return os.path.join(os.path.dirname(os.path.realpath(__file__)), name)


this.waypoints = Waypoints(local_file("waypoints.json"))


def plugin_start():
    this.selected_waypoint = config.get("Kumay3305.target_waypoint")
    if this.selected_waypoint:
        this.target = this.waypoints.info(this.selected_waypoint)

    crash_loc = config.get("Kumay3305.crash_location")
    if crash_loc:
        this.waypoints.update_crash_location(json.loads(crash_loc))
    return "Kumay3305"


def plugin_stop():
    window.destroy()
Exemple #15
0
 def Quit(self):
     Log("simwpt","SimWaypoints::Quit()")
     Waypoints.Quit(self)
     self.waypoints.close()
Exemple #16
0
    import argparse
    from utils import plot_waypoints, plot_control_points
    from scipy import interpolate
    import matplotlib.pyplot as plt
    logging.basicConfig(
        format=
        '[%(levelname)s][%(name)s:%(funcName)s]|%(filename)s:%(lineno)d| %(message)s',
        level=logging.DEBUG)

    parser = argparse.ArgumentParser()
    parser.add_argument('--inputfile', type=str, default='waypoints.txt')
    parser.add_argument('--outputfile',
                        type=str,
                        default='cubicinterpolation.txt')
    parser.add_argument('--samplingstep', type=float, default=0.01)
    args = parser.parse_args()
    solver = BSplineInterpolationSolver()
    waypoints = Waypoints(filename=args.inputfile)
    curve = solver.solve(waypoints)
    plot_waypoints(waypoints)
    plot_control_points(curve)
    curve.write_file(args.outputfile)
    x, y = interpolate.splev(
        np.arange(0, 1.0 + args.samplingstep, args.samplingstep),
        (curve.knot_vector, curve.control_points.T, 3))
    plt.plot(x, y, linestyle='-', label='b-spline interpolation')
    plt.grid()
    plt.axis('equal')
    plt.legend()
    plt.show()
Exemple #17
0
 def __init__(self, registry):
     Log("lmwpt", "LmWaypoints::__init__()")
     self.lmdb = landmarks.OpenDefaultDatabase()
     Waypoints.__init__(self, registry)