use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.
the class StreetVertexIndexServiceImpl method postSetup.
@SuppressWarnings("rawtypes")
private void postSetup() {
for (Vertex gv : graph.getVertices()) {
Vertex v = gv;
/*
* We add all edges with geometry, skipping transit, filtering them out after. We do not
* index transit edges as we do not need them and some GTFS do not have shape data, so
* long straight lines between 2 faraway stations will wreck performance on a hash grid
* spatial index.
*
* If one need to store transit edges in the index, we could improve the hash grid
* rasterizing splitting long segments.
*/
for (Edge e : gv.getOutgoing()) {
if (e instanceof PatternEdge || e instanceof SimpleTransfer)
continue;
LineString geometry = e.getGeometry();
if (geometry == null) {
continue;
}
Envelope env = geometry.getEnvelopeInternal();
if (edgeTree instanceof HashGridSpatialIndex)
((HashGridSpatialIndex) edgeTree).insert(geometry, e);
else
edgeTree.insert(env, e);
}
if (v instanceof TransitStop) {
Envelope env = new Envelope(v.getCoordinate());
transitStopTree.insert(env, v);
}
Envelope env = new Envelope(v.getCoordinate());
verticesTree.insert(env, v);
}
}
use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.
the class TestHopFactory method testBoardAlight.
public void testBoardAlight() throws Exception {
Vertex stop_a = graph.getVertex(feedId + ":A_depart");
Vertex stop_b_depart = graph.getVertex(feedId + ":B_depart");
assertEquals(1, stop_a.getDegreeOut());
assertEquals(3, stop_b_depart.getDegreeOut());
for (Edge e : stop_a.getOutgoing()) {
assertEquals(TransitBoardAlight.class, e.getClass());
assertTrue(((TransitBoardAlight) e).boarding);
}
// TODO: could this ever be a PatternAlight? I think not.
TransitBoardAlight pb = (TransitBoardAlight) stop_a.getOutgoing().iterator().next();
Vertex journey_a_1 = pb.getToVertex();
assertEquals(1, journey_a_1.getDegreeIn());
for (Edge e : journey_a_1.getOutgoing()) {
if (e.getToVertex() instanceof TransitStop) {
assertEquals(TransitBoardAlight.class, e.getClass());
assertTrue(((TransitBoardAlight) e).boarding);
} else {
assertEquals(PatternHop.class, e.getClass());
}
}
}
use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.
the class TestPatternHopFactory method setUp.
public void setUp() throws Exception {
context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
graph = new Graph();
feedId = context.getFeedId().getId();
GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
factory.run(graph);
graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
String[] stops = { feedId + ":A", feedId + ":B", feedId + ":C", feedId + ":D", feedId + ":E", feedId + ":entrance_a", feedId + ":entrance_b" };
for (int i = 0; i < stops.length; ++i) {
TransitStop stop = (TransitStop) (graph.getVertex(stops[i]));
IntersectionVertex front = new IntersectionVertex(graph, "near_1_" + stop.getStopId(), stop.getX() + 0.0001, stop.getY() + 0.0001);
IntersectionVertex back = new IntersectionVertex(graph, "near_2_" + stop.getStopId(), stop.getX() - 0.0001, stop.getY() - 0.0001);
StreetEdge street1 = new StreetEdge(front, back, GeometryUtils.makeLineString(stop.getX() + 0.0001, stop.getY() + 0.0001, stop.getX() - 0.0001, stop.getY() - 0.0001), "street", 100, StreetTraversalPermission.ALL, false);
StreetEdge street2 = new StreetEdge(back, front, GeometryUtils.makeLineString(stop.getX() - 0.0001, stop.getY() - 0.0001, stop.getX() + 0.0001, stop.getY() + 0.0001), "street", 100, StreetTraversalPermission.ALL, true);
}
StreetLinkerModule ttsnm = new StreetLinkerModule();
// Linkers aren't run otherwise
graph.hasStreets = true;
graph.hasTransit = true;
ttsnm.buildGraph(graph, new HashMap<Class<?>, Object>());
}
use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.
the class GraphIndexTest method testSpatialIndex.
public void testSpatialIndex() {
String feedId = graph.getFeedIds().iterator().next();
Stop stopJ = graph.index.stopForId.get(new AgencyAndId(feedId, "J"));
Stop stopL = graph.index.stopForId.get(new AgencyAndId(feedId, "L"));
Stop stopM = graph.index.stopForId.get(new AgencyAndId(feedId, "M"));
TransitStop stopvJ = graph.index.stopVertexForStop.get(stopJ);
TransitStop stopvL = graph.index.stopVertexForStop.get(stopL);
TransitStop stopvM = graph.index.stopVertexForStop.get(stopM);
// There are a two other stops within 100 meters of stop J.
Envelope env = new Envelope(new Coordinate(stopJ.getLon(), stopJ.getLat()));
env.expandBy(SphericalDistanceLibrary.metersToLonDegrees(100, stopJ.getLat()), SphericalDistanceLibrary.metersToDegrees(100));
List<TransitStop> stops = graph.index.stopSpatialIndex.query(env);
assertTrue(stops.contains(stopvJ));
assertTrue(stops.contains(stopvL));
assertTrue(stops.contains(stopvM));
// Query can overselect
assertTrue(stops.size() >= 3);
}
Aggregations