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();
}
}
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)));
}
}
}
}
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));
}
}
}
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;
}
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);
}
Aggregations