Search in sources :

Example 11 with Route

use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getStopsForRoute.

/**
 * Return all stops in any pattern on a given route.
 */
@GET
@Path("/routes/{routeId}/stops")
public Response getStopsForRoute(@PathParam("routeId") String routeIdString) {
    AgencyAndId routeId = GtfsLibrary.convertIdFromString(routeIdString);
    Route route = index.routeForId.get(routeId);
    if (route != null) {
        Set<Stop> stops = Sets.newHashSet();
        Collection<TripPattern> patterns = index.patternsForRoute.get(route);
        for (TripPattern pattern : patterns) {
            stops.addAll(pattern.getStops());
        }
        return Response.status(Status.OK).entity(StopShort.list(stops)).build();
    } else {
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) Route(org.onebusaway.gtfs.model.Route) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 12 with Route

use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getRoute.

/**
 * Return specific route in the graph, for the given ID.
 */
@GET
@Path("/routes/{routeId}")
public Response getRoute(@PathParam("routeId") String routeIdString) {
    AgencyAndId routeId = GtfsLibrary.convertIdFromString(routeIdString);
    Route route = index.routeForId.get(routeId);
    if (route != null) {
        return Response.status(Status.OK).entity(route).build();
    } else {
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 13 with Route

use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getRoutesForStop.

@GET
@Path("/stops/{stopId}/routes")
public Response getRoutesForStop(@PathParam("stopId") String stopId) {
    Stop stop = index.stopForId.get(GtfsLibrary.convertIdFromString(stopId));
    if (stop == null)
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    Set<Route> routes = Sets.newHashSet();
    for (TripPattern pattern : index.patternsForStop.get(stop)) {
        routes.add(pattern.route);
    }
    return Response.status(Status.OK).entity(RouteShort.list(routes)).build();
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) Route(org.onebusaway.gtfs.model.Route) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 14 with Route

use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.

the class GraphIndexTest method testPatternsCoherent.

/**
 * Check that bidirectional relationships between TripPatterns and Trips, Routes, and Stops are coherent.
 */
public void testPatternsCoherent() {
    for (Trip trip : graph.index.tripForId.values()) {
        TripPattern pattern = graph.index.patternForTrip.get(trip);
        assertTrue(pattern.getTrips().contains(trip));
    }
    /* This one depends on a feed where each TripPattern appears on only one route. */
    for (Route route : graph.index.routeForId.values()) {
        for (TripPattern pattern : graph.index.patternsForRoute.get(route)) {
            assertEquals(pattern.route, route);
        }
    }
    for (Stop stop : graph.index.stopForId.values()) {
        for (TripPattern pattern : graph.index.patternsForStop.get(stop)) {
            assertTrue(pattern.stopPattern.containsStop(stop.getId().toString()));
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Route(org.onebusaway.gtfs.model.Route)

Example 15 with Route

use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.

the class TripTimesTest method testBikesAllowed.

@Test
public void testBikesAllowed() {
    Graph graph = new Graph();
    Trip trip = new Trip();
    Route route = new Route();
    trip.setRoute(route);
    List<StopTime> stopTimes = Arrays.asList(new StopTime(), new StopTime());
    TripTimes s = new TripTimes(trip, stopTimes, new Deduplicator());
    RoutingRequest request = new RoutingRequest(TraverseMode.BICYCLE);
    Vertex v = new SimpleConcreteVertex(graph, "", 0.0, 0.0);
    request.setRoutingContext(graph, v, v);
    State s0 = new State(request);
    assertFalse(s.tripAcceptable(s0, 0));
    BikeAccess.setForTrip(trip, BikeAccess.ALLOWED);
    assertTrue(s.tripAcceptable(s0, 0));
    BikeAccess.setForTrip(trip, BikeAccess.NOT_ALLOWED);
    assertFalse(s.tripAcceptable(s0, 0));
}
Also used : SimpleConcreteVertex(org.opentripplanner.routing.graph.SimpleConcreteVertex) Vertex(org.opentripplanner.routing.graph.Vertex) Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) State(org.opentripplanner.routing.core.State) SimpleConcreteVertex(org.opentripplanner.routing.graph.SimpleConcreteVertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Aggregations

Route (org.onebusaway.gtfs.model.Route)90 Trip (org.onebusaway.gtfs.model.Trip)52 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)46 Test (org.junit.Test)33 Stop (org.onebusaway.gtfs.model.Stop)28 Agency (org.onebusaway.gtfs.model.Agency)21 ArrayList (java.util.ArrayList)16 StopTime (org.onebusaway.gtfs.model.StopTime)14 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)12 HashMap (java.util.HashMap)10 Edge (org.opentripplanner.routing.graph.Edge)8 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)7 List (java.util.List)6 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)6 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5