use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.
the class SimpleIsochrone method makePoints.
/**
* @return a map from each vertex to minimum travel time over the course of the day.
*/
private Map<Vertex, Double> makePoints() throws Exception {
rangeCheckParameters();
request = buildRequest();
Router router = otpServer.getRouter(routerId);
Graph graph = router.graph;
// double speed = request.getWalkSpeed();
Coordinate originCoord = request.from.getCoordinate();
if (originCoord == null)
return null;
List<TransitStop> stops = graph.streetIndex.getNearbyTransitStops(originCoord, radiusMeters);
if (stops.isEmpty()) {
LOG.error("No stops found within {} meters.", radiusMeters);
return null;
}
if (shpName == null)
shpName = stops.get(0).getName().split(" ")[0];
StreetVertex origin = new IntersectionVertex(graph, "iso_temp", originCoord.x, originCoord.y);
for (TransitStop stop : stops) {
new StreetTransitLink(origin, stop, false);
LOG.debug("linked to stop {}", stop.getName());
}
request.setRoutingContext(graph, origin, null);
/* Make one request every M minutes over H hours */
int nRequests = (requestTimespanHours * 60) / requestSpacingMinutes;
request.clampInitialWait = (requestSpacingMinutes * 60);
Date date = request.getDateTime();
MinMap<Vertex, Double> points = new MinMap<Vertex, Double>();
for (int r = 0; r < nRequests; r++) {
request.dateTime = date.getTime() / 1000 + r * requestSpacingMinutes * 60;
LOG.debug("date: {} {}", new Date(request.dateTime), request.dateTime);
ShortestPathTree spt = sptService.getShortestPathTree(request, 10);
/* This could even be a good use for a generic SPT merging function */
for (State s : spt.getAllStates()) {
if (stopsOnly && !(s.getVertex() instanceof TransitStop))
continue;
points.putMin(s.getVertex(), (double) (s.getActiveTime()));
}
}
graph.removeVertexAndEdges(origin);
return points;
}
use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.
the class NearbyStopFinder method findNearbyStopsConsideringPatterns.
/**
* Find all unique nearby stops that are the closest stop on some trip pattern.
* Note that the result will include the origin vertex if it is an instance of TransitStop.
* This is intentional: we don't want to return the next stop down the line for trip patterns that pass through the
* origin vertex.
*/
public Set<StopAtDistance> findNearbyStopsConsideringPatterns(Vertex vertex) {
/* Track the closest stop on each pattern passing nearby. */
SimpleIsochrone.MinMap<TripPattern, StopAtDistance> closestStopForPattern = new SimpleIsochrone.MinMap<TripPattern, StopAtDistance>();
/* Iterate over nearby stops via the street network or using straight-line distance, depending on the graph. */
for (NearbyStopFinder.StopAtDistance stopAtDistance : findNearbyStops(vertex)) {
/* Filter out destination stops that are already reachable via pathways or transfers. */
// FIXME why is the above comment relevant here? how does the next line achieve this?
TransitStop ts1 = stopAtDistance.tstop;
if (!ts1.isStreetLinkable())
continue;
/* Consider this destination stop as a candidate for every trip pattern passing through it. */
for (TripPattern pattern : graph.index.patternsForStop.get(ts1.getStop())) {
closestStopForPattern.putMin(pattern, stopAtDistance);
}
}
/* Make a transfer from the origin stop to each destination stop that was the closest stop on any pattern. */
Set<StopAtDistance> uniqueStops = Sets.newHashSet();
uniqueStops.addAll(closestStopForPattern.values());
return uniqueStops;
}
use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.
the class NearbyStopFinder method findNearbyStopsEuclidean.
/**
* Return all stops within a certain radius of the given vertex, using straight-line distance independent of streets.
* If the origin vertex is a TransitStop, the result will include it.
*/
public List<StopAtDistance> findNearbyStopsEuclidean(Vertex originVertex) {
List<StopAtDistance> stopsFound = Lists.newArrayList();
Coordinate c0 = originVertex.getCoordinate();
for (TransitStop ts1 : streetIndex.getNearbyTransitStops(c0, radiusMeters)) {
double distance = SphericalDistanceLibrary.distance(c0, ts1.getCoordinate());
if (distance < radiusMeters) {
Coordinate[] coordinates = new Coordinate[] { c0, ts1.getCoordinate() };
StopAtDistance sd = new StopAtDistance(ts1, distance);
sd.geom = geometryFactory.createLineString(coordinates);
stopsFound.add(sd);
}
}
return stopsFound;
}
use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.
the class StopsAlerts method buildGraph.
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
try {
PrintWriter pw = new PrintWriter(new File(logFile));
pw.printf("%s,%s,%s,%s\n", "stopId", "lon", "lat", "types");
for (TransitStop ts : Iterables.filter(graph.getVertices(), TransitStop.class)) {
StringBuilder types = new StringBuilder();
for (IStopTester stopTester : stopTesters) {
if (stopTester.fulfillDemands(ts, graph)) {
if (types.length() > 0)
types.append(";");
types.append(stopTester.getType());
}
}
if (types.length() > 0) {
pw.printf("%s,%f,%f,%s\n", ts.getStopId(), ts.getCoordinate().x, ts.getCoordinate().y, types.toString());
}
}
pw.close();
} catch (FileNotFoundException e) {
LOG.error("Failed to write StopsAlerts log file", e);
}
}
use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.
the class SampleStopLinker method link.
/**
* Link all transit stops. If makeTransfers is true, create direct transfer
* edges between stops linked to the same pair of vertices. This is important
* e.g. for transit centers where there are many stops on the same street segment;
* we don't want to force the user to walk to the end of the street and back.
*
* If you're not generating transfers via the street network there is no need to make
* transfers at this stage. But if you're not generating transfers via the street network,
* why are you using this module at all?
*/
public void link(boolean makeTransfers) {
if (makeTransfers)
links = HashMultimap.create();
SampleFactory sf = graph.getSampleFactory();
for (TransitStop tstop : Iterables.filter(graph.getVertices(), TransitStop.class)) {
Sample s = sf.getSample(tstop.getLon(), tstop.getLat());
// TODO: stop unlinked annotation
if (s == null)
continue;
new IntersectionTransitLink(tstop, (OsmVertex) s.v0, s.d0);
new IntersectionTransitLink((OsmVertex) s.v0, tstop, s.d0);
new IntersectionTransitLink(tstop, (OsmVertex) s.v1, s.d1);
new IntersectionTransitLink((OsmVertex) s.v1, tstop, s.d1);
if (makeTransfers) {
// save the sample so we can make direct transfers between stops
VertexPair vp = new VertexPair(s.v0, s.v1);
links.put(vp, tstop);
}
}
if (makeTransfers) {
// make direct transfers between stops
for (Collection<TransitStop> tss : links.asMap().values()) {
for (TransitStop ts0 : tss) {
for (TransitStop ts1 : tss) {
// make a geometry
GeometryFactory gf = GeometryUtils.getGeometryFactory();
LineString geom = gf.createLineString(new Coordinate[] { ts0.getCoordinate(), ts1.getCoordinate() });
double dist = SphericalDistanceLibrary.distance(ts0.getLat(), ts0.getLon(), ts1.getLat(), ts1.getLon());
// building unidirectional edge, we'll hit this again in the opposite direction
new SimpleTransfer(ts1, ts1, dist, geom);
}
}
}
}
}
Aggregations