Example #1
0
def _process_stops_in_seg_data(ride_seg, xml_stops, index):
    """
    Process the segment, extracting the stops and getting the bounds of the
    stops.

    @param ride_seg: L{Segment} to process
    @type ride_seg: L{Segment}
    @param xml_stops: C{list} of C{Element}s for stops in rideset
    @type xml_stops: C{list} of C{Element}
    @param index: next index to use for a stop
    @type index: C{int}

    @return: (stops for segment, bounds, updated index)
    @rtype: (C{list} of L{Stop},L{Box},C{int})
    """
    seg_stops = []
    bounds = Box()
    for waypoint, dist in _stop_pts_dist(ride_seg.waypoints):
        if waypoint.stop is not None:
            stop_list = waypoint.stop.split()
            for stop_item in stop_list:
                xml_stop = get_from_id(xml_stops, stop_item.strip())

                new_stop = _parse_stop_xml(xml_stop)
                new_stop.description = " ".join(new_stop.description.split())
                new_stop.distance = ride_seg.start_dist + dist
                new_stop.off_route = new_stop.calculate_distance(waypoint)
                new_stop.index = index
                index += 1

                seg_stops.append(new_stop)
                bounds.expand_to_point(new_stop.lat, new_stop.lon)

    return seg_stops, bounds, index
Example #2
0
def process_ride_stops(seg_set, xml_segs, xml_stops):
    """
    Process the stop references for the given ride and generate a list of
    L{Stop} objects for it and the bounding box for all of the stops.

    @param seg_set: C{list} of L{Segment} objects for the ride
    @type seg_set: C{list} of L{Segment} objects
    @param xml_segs: C{list} of C{Element} segment objects for this ride
    @type xml_segs: C{list} of C{Element}s
    @param xml_stops: C{list} of C{Element} stop objects
    @type xml_stops: C{list} of C{Element}s

    @return: (C{list} of L{Stop},C{bounds})
    @rtype: (C{list},L{Box})
    """
    index = 1
    stop_list = []
    bounds = Box()
    for ride_seg in seg_set:
        new_stops, new_bounds, index = \
            _process_stops_in_seg_data(ride_seg, xml_stops, index)
        stop_list.extend(new_stops)
        bounds.expand_to_box(new_bounds)

    return stop_list, bounds
Example #3
0
File: poi.py Project: jfarrimo/sabx
def process_ride_pois(seg_set, xml_segs, xml_pois):
    """
    Process the point of interest references for the given ride and generate a
    list of L{Poi} objects for it and the bounding box for all of the POIs.

    @param seg_set: C{list} of L{Segment} objects for the ride
    @type seg_set: C{list} of L{Segment} objects
    @param xml_segs: C{list} of C{Element} segment objects for this ride
    @type xml_segs: C{list} of C{Element}s
    @param xml_pois: C{list} of C{Element} point of interest objects
    @type xml_pois: C{list} of C{Element}s

    @return: (C{list} of L{Poi},C{bounds})
    @rtype: (C{list},L{Box})
    """
    index = 1
    poi_list = []
    bounds = Box()
    for ride_seg in seg_set:
        new_pois, new_bounds, index = \
            _process_pois_in_seg_data(ride_seg, xml_pois, index)
        poi_list.extend(new_pois)
        bounds.expand_to_box(new_bounds)

    return poi_list, bounds
Example #4
0
File: poi.py Project: jfarrimo/sabx
def _process_pois_in_seg_data(ride_seg, xml_pois, index):
    """
    Process the segment, extracting the POIs and getting the bounds of the
    POIs.

    @param ride_seg: L{Segment} to process
    @type ride_seg: L{Segment}
    @param xml_pois: C{list} of C{Element}s for POIs in rideset
    @type xml_pois: C{list} of C{Element}
    @param index: next index to use for a POI
    @type index: C{int}

    @return: (POIs for segment, bounds, updated index)
    @rtype: (C{list} of L{Poi},L{Box},C{int})
    """
    seg_pois = []
    bounds = Box()
    for waypoint, dist in _poi_pts_dist(ride_seg.waypoints):
        if waypoint.poi is not None:
            poi_list = waypoint.poi.split()
            for poi_item in poi_list:
                xml_poi = get_from_id(xml_pois, poi_item.strip())

                new_poi = _parse_poi_xml(xml_poi)
                new_poi.description = " ".join(new_poi.description.split())
                new_poi.distance = ride_seg.start_dist + dist
                new_poi.off_route = new_poi.calculate_distance(waypoint)
                new_poi.index = index
                index += 1

                seg_pois.append(new_poi)
                bounds.expand_to_point(new_poi.lat, new_poi.lon)

    return seg_pois, bounds, index
Example #5
0
def process_rides(xml_tree, correct_ele=True):
    """
    Process the rides in the XML tree and generate a list of L{Ride} objects
    and the bounding box for all of the rides.

    @param xml_tree: root of C{Element} tree that has rides in it
    @type xml_tree: C{Element} or C{ElementTree}
    @param correct_ele: make sure that the segment elevations match-up?
    @type correct_ele: C{boolean}

    @return: (C{list} of L{Ride}s,C{bounds} of ride)
    @rtype: (C{list} of L{Ride},L{Box})
    """
    check_version(xml_tree)
    xml_rides = xml_tree.findall('ride')
    xml_parking_places = xml_tree.findall('parking')
    xml_segs = xml_tree.findall('segment')
    xml_turns = xml_tree.findall('turn')
    xml_stops = xml_tree.findall('stop')
    xml_pois = xml_tree.findall('poi')

    bounds = Box()
    ride_list = []
    for ride_index, xml_ride in enumerate(xml_rides):
        new_ride = _process_ride(ride_index, xml_ride, xml_parking_places, 
                                 xml_segs, xml_turns, xml_stops, xml_pois,
                                 correct_ele)
        bounds.expand_to_box(new_ride.bounds)
        ride_list.append(new_ride)

    return ride_list, bounds
Example #6
0
def process_ride_segments(xml_ride, xml_segs, correct_ele=True):
    """
    Process the segment references for the given ride and generate a list of
    L{Segment} objects for it and the bounding box for all of the segments.

    @param xml_ride: C{Element} for a ride
    @type xml_ride: C{Element}
    @param xml_segs: C{list} of C{Element} segment objects for this rideset
    @type xml_segs: C{list} of C{Element}s
    @param correct_ele: make sure that the segment elevations match-up?
    @type correct_ele: C{boolean}

    @return: (C{list} of L{Segment},C{bounds})
    @rtype: (C{list},L{Box})
    """
    """ Process the segments in the ride. """
    cum_distance = 0.0
    bounds = Box()

    ride_segs = _get_ride_segs(xml_ride, xml_segs)
    if correct_ele:
        _correct_elevations(ride_segs)
    _connect_segments_to_following_segment(ride_segs)
    for index, seg in enumerate(ride_segs):
        _process_segment(seg, index, cum_distance)
        cum_distance += seg.length
        bounds.expand_to_box(seg.bounds)

    return ride_segs, bounds
Example #7
0
def _process_bounds(ride, seg_bounds, stop_bounds, poi_bounds):
    """
    Creating a bounding box that includes the bounds for the parking, segments,
    stops, and pois for this ride.

    @param ride: C{Ride} to process
    @type ride: C{Ride}
    @param seg_bounds: bounding C{Box} for segments
    @type seg_bounds: C{Box}
    @param stop_bounds: bounding C{Box} for stops
    @type stop_bounds: C{Box}
    @param poi_bounds: bounding C{Box} for pois
    @type poi_bounds: C{Box}

    @return: bounding box containing everything
    @rtype: L{Box}
    """
    bounds = Box()
    bounds.expand_to_point(ride.parking.lat, ride.parking.lon)
    bounds.expand_to_box(seg_bounds)
    bounds.expand_to_box(stop_bounds)
    bounds.expand_to_box(poi_bounds)
    return bounds