Пример #1
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
Пример #2
0
    def intermediate_points(self, numpoints=101, connection="greatcircle"):
        """Compute intermediate points between the waypoints.

        See mss_util.path_points() for additional arguments.

        Returns lats, lons.
        """
        path = [[wp.lat, wp.lon, wp.utc_time] for wp in self.waypoints]
        return utils.path_points(path,
                                 numpoints=numpoints,
                                 connection=connection)
Пример #3
0
def test_pathpoints():
    p1 = [0, 0, datetime.datetime(2012, 7, 1, 10, 30)]
    p2 = [10, 10, datetime.datetime(2012, 7, 1, 10, 40)]
    p3 = [-20, 20, datetime.datetime(2012, 7, 1, 10, 40)]

    result = utils.path_points([p1, p1], 100, "linear")
    assert all(len(_x) == 100 for _x in result)
    assert all(result[i][0] == p1[i] for i in range(3))
    assert all(result[i][-1] == p1[i] for i in range(3))

    result = utils.path_points([p1, p1], 100, "greatcircle")
    assert all(len(_x) == 100 for _x in result)
    assert all(result[i][0] == p1[i] for i in range(3))
    assert all(result[i][-1] == p1[i] for i in range(3))

    result = utils.path_points([p1, p2], 200, "linear")
    assert all(len(_x) == 200 for _x in result)
    assert all(result[i][0] == p1[i] for i in range(3))
    assert all(result[i][-1] == p2[i] for i in range(3))

    result = utils.path_points([p1, p2], 200, "greatcircle")
    assert all(len(_x) == 200 for _x in result)
    assert all(result[i][0] == p1[i] for i in range(3))
    assert all(result[i][-1] == p2[i] for i in range(3))

    result = utils.path_points([p1, p2, p3], 100, "linear")
    assert all(len(_x) == 100 for _x in result)
    assert all(result[i][0] == p1[i] for i in range(3))
    assert all(result[i][-1] == p3[i] for i in range(3))

    result = utils.path_points([p1, p2, p3], 100, "greatcircle")
    assert all(len(_x) == 100 for _x in result)
    assert all(result[i][0] == p1[i] for i in range(3))
    assert all(result[i][-1] == p3[i] for i in range(3))
Пример #4
0
 def _set_vertical_section_path(self,
                                vsec_path,
                                vsec_numpoints=101,
                                vsec_path_connection='linear'):
     """
     """
     logging.debug("computing %i interpolation points, connection: %s",
                   vsec_numpoints, vsec_path_connection)
     now = datetime.now()
     self.lats, self.lons, _ = utils.path_points(
         [(_x, _y, now) for _x, _y in vsec_path],
         numpoints=vsec_numpoints,
         connection=vsec_path_connection)
     self.vsec_path = vsec_path
     self.vsec_numpoints = vsec_numpoints
     self.vsec_path_connection = vsec_path_connection
Пример #5
0
 def _set_linear_section_path(self,
                              lsec_path,
                              lsec_numpoints=101,
                              lsec_path_connection='linear'):
     """
     """
     logging.debug("computing %i interpolation points, connection: %s",
                   lsec_numpoints, lsec_path_connection)
     now = datetime.now()
     self.lats, self.lons, self.alts, _ = utils.path_points(
         [(_x, _y, _z, now) for _x, _y, _z in lsec_path],
         numpoints=lsec_numpoints,
         connection=lsec_path_connection,
         contains_altitude=True)
     self.lsec_path = lsec_path
     self.lsec_numpoints = lsec_numpoints
     self.lsec_path_connection = lsec_path_connection