Example #1
0
    def test_greatcircle(self):
        ref_times = [datetime.datetime(2012, 7, 12, 10, 30), datetime.datetime(2012, 7, 12, 10, 35)]
        ref_lats = [0, 10]
        ref_lons = [0, 0]

        lats, lons, times = utils.latlon_points([ref_lats[0], ref_lons[0], ref_times[0]],
                                                [ref_lats[1], ref_lons[1], ref_times[1]],
                                                numpoints=2, connection="greatcircle")
        assert len(lats) == len(ref_lats)
        assert all(lats == ref_lats)
        assert len(lons) == len(ref_lons)
        assert all(lons == ref_lons)
        assert len(times) == len(ref_times)
        assert all(times == ref_times)

        lats, lons, times = utils.latlon_points([ref_lats[0], ref_lons[0], ref_times[0]],
                                                [ref_lats[1], ref_lons[1], ref_times[1]],
                                                numpoints=3, connection="linear")
        assert len(lats) == 3
        assert len(lons) == 3
        assert len(times) == 3
        assert all(lats == [0, 5, 10])

        ref_lats = [0, 0]
        ref_lons = [0, 10]
        lats, lons, times = utils.latlon_points([ref_lats[0], ref_lons[0], ref_times[0]],
                                                [ref_lats[1], ref_lons[1], ref_times[1]],
                                                numpoints=3, connection="linear")
        assert len(lats) == 3
        assert len(lons) == 3
        assert len(times) == 3
        assert all(lons == [0, 5, 10])
        assert(times[1] - times[0] == times[2] - times[1])
Example #2
0
    def get_lat_lon(self, event):
        x = event.xdata
        wpm = self.waypoints_model
        vertices = self.pathpatch.get_path().vertices
        vertices = np.ndarray.tolist(vertices)
        for index, vertex in enumerate(vertices):
            vertices[index].append(datetime.datetime(2012, 7, 1, 10, 30))
        best_index = 1
        # if x axis has increasing coordinates
        if vertices[-1][0] > vertices[0][0]:
            for index, vertex in enumerate(vertices):
                if x >= vertex[0]:
                    best_index = index + 1
        # if x axis has decreasing coordinates
        else:
            for index, vertex in enumerate(vertices):
                if x <= vertex[0]:
                    best_index = index + 1
        # number of subcoordinates is determined by difference in x coordinates
        number_of_intermediate_points = math.floor(vertices[best_index][0] -
                                                   vertices[best_index - 1][0])
        intermediate_vertices_list = path_points(
            [vertices[best_index - 1], vertices[best_index]],
            number_of_intermediate_points)
        wp1Array = [
            wpm.waypoint_data(best_index - 1).lat,
            wpm.waypoint_data(best_index - 1).lon,
            datetime.datetime(2012, 7, 1, 10, 30)
        ]
        wp2Array = [
            wpm.waypoint_data(best_index).lat,
            wpm.waypoint_data(best_index).lon,
            datetime.datetime(2012, 7, 1, 10, 30)
        ]
        intermediate_waypoints_list = latlon_points(
            wp1Array,
            wp2Array,
            number_of_intermediate_points,
            connection="greatcircle")

        # best_index1 is the best index among the intermediate coordinates to fit the hovered point
        # if x axis has increasing coordinates
        best_index1 = 1
        if vertices[-1][0] > vertices[0][0]:
            for index, vertex in enumerate(intermediate_vertices_list[0]):
                if x >= vertex:
                    best_index1 = index + 1
        # if x axis has decreasing coordinates
        else:
            for index, vertex in enumerate(intermediate_vertices_list[0]):
                if x <= vertex:
                    best_index1 = index + 1
        # depends if best_index1 or best_index1 - 1 on closeness to left or right neighbourhood
        return [
            intermediate_waypoints_list[0][best_index1 - 1],
            intermediate_waypoints_list[1][best_index1 - 1]
        ], best_index