Search in sources :

Example 6 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getStopsInRadius.

/**
 * Return a list of all stops within a circle around the given coordinate.
 */
@GET
@Path("/stops")
public Response getStopsInRadius(@QueryParam("minLat") Double minLat, @QueryParam("minLon") Double minLon, @QueryParam("maxLat") Double maxLat, @QueryParam("maxLon") Double maxLon, @QueryParam("lat") Double lat, @QueryParam("lon") Double lon, @QueryParam("radius") Double radius) {
    /* When no parameters are supplied, return all stops. */
    if (uriInfo.getQueryParameters().isEmpty()) {
        Collection<Stop> stops = index.stopForId.values();
        return Response.status(Status.OK).entity(StopShort.list(stops)).build();
    }
    /* If any of the circle parameters are specified, expect a circle not a box. */
    boolean expectCircle = (lat != null || lon != null || radius != null);
    if (expectCircle) {
        if (lat == null || lon == null || radius == null || radius < 0) {
            return Response.status(Status.BAD_REQUEST).entity(MSG_400).build();
        }
        if (radius > MAX_STOP_SEARCH_RADIUS) {
            radius = MAX_STOP_SEARCH_RADIUS;
        }
        List<StopShort> stops = Lists.newArrayList();
        Coordinate coord = new Coordinate(lon, lat);
        for (TransitStop stopVertex : streetIndex.getNearbyTransitStops(new Coordinate(lon, lat), radius)) {
            double distance = SphericalDistanceLibrary.fastDistance(stopVertex.getCoordinate(), coord);
            if (distance < radius) {
                stops.add(new StopShort(stopVertex.getStop(), (int) distance));
            }
        }
        return Response.status(Status.OK).entity(stops).build();
    } else {
        /* We're not circle mode, we must be in box mode. */
        if (minLat == null || minLon == null || maxLat == null || maxLon == null) {
            return Response.status(Status.BAD_REQUEST).entity(MSG_400).build();
        }
        if (maxLat <= minLat || maxLon <= minLon) {
            return Response.status(Status.BAD_REQUEST).entity(MSG_400).build();
        }
        List<StopShort> stops = Lists.newArrayList();
        Envelope envelope = new Envelope(new Coordinate(minLon, minLat), new Coordinate(maxLon, maxLat));
        for (TransitStop stopVertex : streetIndex.getTransitStopForEnvelope(envelope)) {
            stops.add(new StopShort(stopVertex.getStop()));
        }
        return Response.status(Status.OK).entity(stops).build();
    }
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) Coordinate(com.vividsolutions.jts.geom.Coordinate) StopShort(org.opentripplanner.index.model.StopShort) Envelope(com.vividsolutions.jts.geom.Envelope) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 7 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class TransitToTaggedStopsModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    LOG.info("Linking transit stops to tagged bus stops...");
    index = new StreetVertexIndexServiceImpl(graph);
    // iterate over a copy of vertex list because it will be modified
    ArrayList<Vertex> vertices = new ArrayList<>();
    vertices.addAll(graph.getVertices());
    for (TransitStop ts : Iterables.filter(vertices, TransitStop.class)) {
        // if the street is already linked there is no need to linked it again,
        // could happened if using the prune isolated island
        boolean alreadyLinked = false;
        for (Edge e : ts.getOutgoing()) {
            if (e instanceof StreetTransitLink) {
                alreadyLinked = true;
                break;
            }
        }
        if (alreadyLinked)
            continue;
        // entrances
        if (ts.isEntrance() || !ts.hasEntrances()) {
            boolean wheelchairAccessible = ts.hasWheelchairEntrance();
            if (!connectVertexToStop(ts, wheelchairAccessible)) {
                LOG.debug("Could not connect " + ts.getStopCode() + " at " + ts.getCoordinate().toString());
            // LOG.warn(graph.addBuilderAnnotation(new StopUnlinked(ts)));
            }
        }
    }
}
Also used : TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) ArrayList(java.util.ArrayList) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Edge(org.opentripplanner.routing.graph.Edge) StreetVertexIndexServiceImpl(org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl)

Example 8 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class MultiProfileStateStore method mergeStates.

/**
 * merge similar states (states that have come from the same place on different patterns)
 */
public void mergeStates() {
    Set<TransitStop> touchedStopVertices = new HashSet<TransitStop>(states.keySet());
    for (TransitStop tstop : touchedStopVertices) {
        Collection<ProfileState> pss = states.get(tstop);
        // find states that have come from the same place
        Multimap<ProfileState, ProfileState> foundStates = ArrayListMultimap.create();
        for (Iterator<ProfileState> it = pss.iterator(); it.hasNext(); ) {
            ProfileState ps = it.next();
            foundStates.put(ps.previous, ps);
        }
        pss.clear();
        // merge them now
        for (Collection<ProfileState> states : foundStates.asMap().values()) {
            if (states.size() == 1)
                pss.addAll(states);
            else
                pss.add(ProfileState.merge(states, true));
        }
    }
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) HashSet(java.util.HashSet)

Example 9 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class GraphIndexTest method testIdLookup.

public void testIdLookup() {
    /* Graph vertices */
    for (Vertex vertex : graph.index.vertexForId.values()) {
        if (vertex instanceof TransitStop) {
            Stop stop = ((TransitStop) vertex).getStop();
            Vertex index_vertex = graph.index.stopVertexForStop.get(stop);
            assertEquals(index_vertex, vertex);
        }
    }
    /* Agencies */
    String feedId = graph.getFeedIds().iterator().next();
    Agency agency;
    agency = graph.index.agenciesForFeedId.get(feedId).get("azerty");
    assertNull(agency);
    agency = graph.index.agenciesForFeedId.get(feedId).get("agency");
    assertEquals(agency.getId(), "agency");
    assertEquals(agency.getName(), "Fake Agency");
    /* Stops */
    graph.index.stopForId.get(new AgencyAndId("X", "Y"));
/* Trips */
// graph.index.tripForId;
// graph.index.routeForId;
// graph.index.serviceForId;
// graph.index.patternForId;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Agency(org.onebusaway.gtfs.model.Agency) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop)

Example 10 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class TestTransfers method createSimpleTransfer.

/**
 * Create simple transfer edge between two vertices given their labels
 * @param from is label of from vertex
 * @param to is label of to vertex
 * @param distance is distance of transfer
 */
private void createSimpleTransfer(String from, String to, int distance) {
    TransitStop fromv = ((TransitStop) graph.getVertex(from));
    TransitStop tov = ((TransitStop) graph.getVertex(to));
    new SimpleTransfer(fromv, tov, distance, null);
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) SimpleTransfer(org.opentripplanner.routing.edgetype.SimpleTransfer)

Aggregations

TransitStop (org.opentripplanner.routing.vertextype.TransitStop)49 Stop (org.onebusaway.gtfs.model.Stop)20 Vertex (org.opentripplanner.routing.graph.Vertex)18 Edge (org.opentripplanner.routing.graph.Edge)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)13 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)12 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)11 Graph (org.opentripplanner.routing.graph.Graph)10 Envelope (com.vividsolutions.jts.geom.Envelope)8 LineString (com.vividsolutions.jts.geom.LineString)8 ArrayList (java.util.ArrayList)8 State (org.opentripplanner.routing.core.State)8 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)8 Agency (org.onebusaway.gtfs.model.Agency)7 Trip (org.onebusaway.gtfs.model.Trip)7 SimpleTransfer (org.opentripplanner.routing.edgetype.SimpleTransfer)7 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)7 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)7 Route (org.onebusaway.gtfs.model.Route)6