示例#1
0
    def AddTrip(self,
                schedule=None,
                headsign=None,
                service_period=None,
                trip_id=None):
        """Add a trip to this route.

    Args:
      schedule: a Schedule object which will hold the new trip or None to use
        the schedule of this route.
      headsign: headsign of the trip as a string
      service_period: a ServicePeriod object or None to use
        schedule.GetDefaultServicePeriod()
      trip_id: optional trip_id for the new trip

    Returns:
      a new Trip object
    """
        if schedule is None:
            assert self._schedule is not None
            schedule = self._schedule
        if trip_id is None:
            trip_id = util.FindUniqueId(schedule.trips)
        if service_period is None:
            service_period = schedule.GetDefaultServicePeriod()
        trip_class = self.GetGtfsFactory().Trip
        trip_obj = trip_class(route=self,
                              headsign=headsign,
                              service_period=service_period,
                              trip_id=trip_id)
        schedule.AddTripObject(trip_obj)
        return trip_obj
示例#2
0
 def NewDefaultAgency(self, **kwargs):
   """Create a new Agency object and make it the default agency for this Schedule"""
   agency = self._gtfs_factory.Agency(**kwargs)
   if not agency.agency_id:
     agency.agency_id = util.FindUniqueId(self._agencies)
   self._default_agency = agency
   self.SetDefaultAgency(agency, validate=False)  # Blank agency won't validate
   return agency
示例#3
0
 def NewDefaultServicePeriod(self):
   """Create a new ServicePeriod object, make it the default service period and
   return it. The default service period is used when you create a trip without
   providing an explict service period. """
   service_period = self._gtfs_factory.ServicePeriod()
   service_period._cursor_factory = self
   service_period.service_id = util.FindUniqueId(self.service_periods)
   # blank service won't validate in AddServicePeriodObject
   self.SetDefaultServicePeriod(service_period, validate=False)
   return service_period
示例#4
0
  def AddStop(self, lat, lng, name, stop_id=None):
    """Add a stop to this schedule.

    Args:
      lat: Latitude of the stop as a float or string
      lng: Longitude of the stop as a float or string
      name: Name of the stop, which will appear in the feed
      stop_id: stop_id of the stop or None, in which case a unique id is picked

    Returns:
      A new Stop object
    """
    if stop_id is None:
      stop_id = util.FindUniqueId(self.stops)
    stop = self._gtfs_factory.Stop(stop_id=stop_id, lat=lat, lng=lng, name=name)
    self.AddStopObject(stop)
    return stop
示例#5
0
  def AddRoute(self, short_name, long_name, route_type, route_id=None):
    """Add a route to this schedule.

    Args:
      short_name: Short name of the route, such as "71L"
      long_name: Full name of the route, such as "NW 21st Ave/St Helens Rd"
      route_type: A type such as "Tram", "Subway" or "Bus"
      route_id: id of the route or None, in which case a unique id is picked
    Returns:
      A new Route object
    """
    if route_id is None:
      route_id = util.FindUniqueId(self.routes)
    route = self._gtfs_factory.Route(short_name=short_name, long_name=long_name,
                        route_type=route_type, route_id=route_id)
    route.agency_id = self.GetDefaultAgency().agency_id
    self.AddRouteObject(route)
    return route