예제 #1
0
def split(s, t, speed):
    """
    returns points between s(ource) and t(arget) at intervals of size @speed
    """
    s = LatLon(Latitude(s[1]), Longitude(s[0]))

    t = LatLon(Latitude(t[1]), Longitude(t[0]))

    heading = s.heading_initial(t)

    fine = [
        (s.lon.decimal_degree, s.lat.decimal_degree),
    ]
    wp = s

    while True:
        dst = wp.offset(heading, speed / 1000.0)

        if dst.distance(t) * 1000.0 > speed:
            fine.append((dst.lon.decimal_degree, dst.lat.decimal_degree))
            wp = dst
        else:
            fine.append((t.lon.decimal_degree, t.lat.decimal_degree))
            break

    return fine
예제 #2
0
    def update(self, new_point, update_speed=False):
        """
        updates time stamp

        uses @new_point to update:
         - point
         - heading
         - destination_heading
         - speed, if update_speed=True

        """

        if 'coordinates' in self.point:
            a = LatLon(Longitude(self.point['coordinates'][1]),
                       Latitude(self.point['coordinates'][0]))
        else:
            a = LatLon(Longitude(self.point[1]),
                       Latitude(self.point[0]))

        if 'coordinates' in new_point:
            b = LatLon(Longitude(new_point['coordinates'][1]),
                       Latitude(new_point['coordinates'][0]))
        else:
            b = LatLon(Longitude(new_point[1]),
                       Latitude(new_point[0]))

        if 'coordinates' in self.destination:
            c = LatLon(Longitude(self.destination['coordinates'][1]),
                       Latitude(self.destination['coordinates'][0]))
        else:
            c = LatLon(Longitude(self.destination[1]),
                       Latitude(self.destination[0]))

        self.heading = a.heading_initial(b)
        self.destination_heading = b.heading_initial(c)

        if update_speed:
            tdelta = datetime.now() - self.stamp
            seconds = tdelta.total_seconds()
            distance = a.distance(b) / 1000.0
            self.speed = distance / seconds

        self.stamp = datetime.now()
        self.point = new_point
        self.save()
예제 #3
0
def get_heading(start, end):
    """
    Get heading from start point to end point.
    """
    start = LatLon(Latitude(start['lat']), Longitude(start['lng']))
    end = LatLon(Latitude(end['lat']), Longitude(end['lng']))
    heading = start.heading_initial(end)

    return '{0:.4f}'.format(heading)
예제 #4
0
 def get_distance_and_heading(self, pos):
     """Get distance meters and heading degrees
     to passed position.
     """
     p1 = LatLon(self.lat, self.lon)
     p2 = LatLon(pos.lat, pos.lon)
     distance = p1.distance(p2)  # km
     distance *= 1000  # m
     heading = p1.heading_initial(p2)  # degree
     if heading < 0:
         heading += 360
     return distance, heading
예제 #5
0
def waypoints(coords, step):
    for i in range(1, len(coords)):
        a = LatLon(Latitude(b.point[1]), Longitude(b.point[0]))
        c = LatLon(Latitude(coords[i][1]), Longitude(coords[i][0]))
        while a.distance(c) > step:
            dst = a.offset(a.heading_initial(c), step)
            yield [dst.lon.decimal_degree, dst.lat.decimal_degree]
            a = LatLon(Latitude(b.point[1]), Longitude(b.point[0]))
            c = LatLon(Latitude(coords[i][1]), Longitude(coords[i][0]))

        print "reached waypoint %s" % c
        yield [coords[i][0], coords[i][1]]
예제 #6
0
    def heading_to(self, other_point):
        """
        heading from my point to @other_point
        """
        if 'coordinates' in self.point:
            a = LatLon(Longitude(self.point['coordinates'][1]),
                       Latitude(self.point['coordinates'][0]))
        else:
            a = LatLon(Longitude(self.point[1]),
                       Latitude(self.point[0]))

        b = LatLon(Longitude(other_point[1]),
                   Latitude(other_point[0]))

        return a.heading_initial(b)
예제 #7
0
        shifted_north_coordinates_lon = []
        shifted_north_seg_lats = []
        shifted_north_seg_longs = []
        time_segmentation_start = time.time()
        if segmentation_1:
            for index_outer, line_outer in enumerate(lines):
                for index, line_inner in enumerate(lines):
                    if index != index_outer:
                        for seg_start, seg_end in zip(line_inner.coords[0:-1],
                                                      line_inner.coords[1:]):
                            # create two LatLong instances
                            seg_start_lat_long = LatLon(
                                seg_start[0], seg_start[1])
                            seg_end_lat_long = LatLon(seg_end[0], seg_end[1])
                            # compute heading from start of segment to end of segment
                            heading = seg_start_lat_long.heading_initial(
                                seg_end_lat_long)
                            # offset startpoint perpendicular to heading with given distance
                            # fist towards north, handle negative headings correctly
                            if heading - 90 < 0:
                                heading_north = 270 + heading
                            else:
                                heading_north = heading - 90
                            offset_north_start = seg_start_lat_long.offset(
                                heading_north, 1.0 * dist / 1000)
                            offset_north_end = seg_end_lat_long.offset(
                                heading_north, 1.0 * dist / 1000)

                            shifted_north_coordinates_lat.append(
                                offset_north_start.lat)
                            shifted_north_coordinates_lon.append(
                                offset_north_start.lon)