Ejemplo n.º 1
0
def bearing_splitter(points_set, degree_threshold, min_length):
    segments = []
    segment = GPXTrackSegment()
    previous_bearing = None
    idx = 0

    while idx < len(points_set) - 1:
        current_bearing = util.compass_bearing(points_set[idx], points_set[idx + 1])
        if previous_bearing is not None:
            diff_bearing = abs(previous_bearing - current_bearing)
            if diff_bearing > 180:
                diff_bearing = abs(diff_bearing - 360)
            if diff_bearing > degree_threshold:
                segment.points.append(points_set[idx])
                if segment.length_2d() > min_length:
                    segments.append(segment)
                previous_bearing = None
                segment = GPXTrackSegment()
                # Not increase index. Next iteration must restart from this point
            else:
                segment.points.append(points_set[idx])
                previous_bearing = current_bearing
                idx += 1
        else:
            segment.points.append(points_set[idx])
            previous_bearing = current_bearing
            idx += 1

    segment.points.append(points_set[idx])  # append last point
    if segment.length_2d() > min_length:
        segments.append(segment)

    return segments
Ejemplo n.º 2
0
    def __init__(self, segment: GPXTrackSegment, num_points_path: int = 25) -> None:
        """
        Construct GpxSegmentStats object.
        
        :param: segment:         GPX track segment
        :param: num_points_path: Maximal length of points in path features
        """
        self.name = getattr(segment, 'name', 'NotAvailable')
        self.length2d = segment.length_2d()
        self.length3d = segment.length_3d()
        self.duration = float(segment.get_duration()) \
            if segment.get_duration() is not None else float(-1)
        self.moving_time = segment.get_moving_data().moving_time
        self.stopped_time = segment.get_moving_data().stopped_time

        self.total_uphill = segment.get_uphill_downhill().uphill
        self.total_downhill = segment.get_uphill_downhill().downhill

        self.path = convert_path_to_feature(segment, num_points_path)