use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class TestGeometryAndBlockProcessor method setUp.
public void setUp() throws Exception {
graph = new Graph();
this.issueStore = new DataImportIssueStore(true);
context = contextBuilder(ConstantsForTests.FAKE_GTFS).withIssueStoreAndDeduplicator(graph).build();
feedId = context.getFeedId().getId();
GeometryAndBlockProcessor factory = new GeometryAndBlockProcessor(context);
factory.run(graph, issueStore);
graph.putService(CalendarServiceData.class, context.getCalendarServiceData());
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) {
TransitStopVertex stop = (TransitStopVertex) (graph.getVertex(stops[i]));
IntersectionVertex front = new IntersectionVertex(graph, "near_1_" + stop.getStop().getId(), stop.getX() + 0.0001, stop.getY() + 0.0001);
IntersectionVertex back = new IntersectionVertex(graph, "near_2_" + stop.getStop().getId(), 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.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class GraphPathToItineraryMapper method makePlace.
/**
* Make a {@link Place} to add to a {@link Leg}.
*
* @param vertex The {@link Vertex} at the {@link State}.
* @param stop The {@link Stop} associated with the {@link Vertex}.
* @param requestedLocale The locale to use for all text attributes.
* @return The resulting {@link Place} object.
*/
private static Place makePlace(Vertex vertex, Stop stop, Locale requestedLocale) {
String name = vertex.getName(requestedLocale);
// We use name in TemporaryStreetLocation since this name generation already happened when temporary location was generated
if (vertex instanceof StreetVertex && !(vertex instanceof TemporaryStreetLocation)) {
name = ((StreetVertex) vertex).getIntersectionName(requestedLocale).toString(requestedLocale);
}
Place place = new Place(vertex.getLat(), vertex.getLon(), name);
if (vertex instanceof TransitStopVertex) {
place.stopId = stop.getId();
place.stopCode = stop.getCode();
place.platformCode = stop.getCode();
place.zoneId = stop.getFirstZoneAsString();
place.vertexType = VertexType.TRANSIT;
} else if (vertex instanceof BikeRentalStationVertex) {
place.bikeShareId = ((BikeRentalStationVertex) vertex).getId();
LOG.trace("Added bike share Id {} to place", place.bikeShareId);
place.vertexType = VertexType.BIKESHARE;
} else if (vertex instanceof BikeParkVertex) {
place.vertexType = VertexType.BIKEPARK;
} else {
place.vertexType = VertexType.NORMAL;
}
return place;
}
use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class StreetVertexIndex 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()) {
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 TransitStopVertex) {
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.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class StreetVertexIndex method getNearbyTransitStops.
/**
* Get all transit stops within a given distance of a coordinate
* @return The transit stops within a certain radius of the given location.
*/
public List<TransitStopVertex> getNearbyTransitStops(Coordinate coordinate, double radius) {
Envelope env = new Envelope(coordinate);
env.expandBy(SphericalDistanceLibrary.metersToLonDegrees(radius, coordinate.y), SphericalDistanceLibrary.metersToDegrees(radius));
List<TransitStopVertex> nearby = getTransitStopForEnvelope(env);
List<TransitStopVertex> results = new ArrayList<TransitStopVertex>();
for (TransitStopVertex v : nearby) {
if (SphericalDistanceLibrary.distance(v.getCoordinate(), coordinate) <= radius) {
results.add(v);
}
}
return results;
}
use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class LinkStopToPlatformTest method before.
@Before
public void before() {
// Set up transit platform
graph = new Graph();
ArrayList<IntersectionVertex> vertices = new ArrayList<IntersectionVertex>();
vertices.add(new IntersectionVertex(graph, "1", 10.22054, 59.13568, "Platform vertex 1"));
vertices.add(new IntersectionVertex(graph, "2", 10.22432, 59.13519, "Platform vertex 2"));
vertices.add(new IntersectionVertex(graph, "3", 10.22492, 59.13514, "Platform vertex 3"));
vertices.add(new IntersectionVertex(graph, "4", 10.22493, 59.13518, "Platform vertex 4"));
vertices.add(new IntersectionVertex(graph, "5", 10.22056, 59.13575, "Platform vertex 5"));
AreaEdgeList areaEdgeList = new AreaEdgeList();
ArrayList<AreaEdge> edges = new ArrayList<AreaEdge>();
edges.add(createAreaEdge(vertices.get(0), vertices.get(1), areaEdgeList, "edge 1"));
edges.add(createAreaEdge(vertices.get(1), vertices.get(2), areaEdgeList, "edge 2"));
edges.add(createAreaEdge(vertices.get(2), vertices.get(3), areaEdgeList, "edge 3"));
edges.add(createAreaEdge(vertices.get(3), vertices.get(4), areaEdgeList, "edge 4"));
edges.add(createAreaEdge(vertices.get(4), vertices.get(0), areaEdgeList, "edge 5"));
edges.add(createAreaEdge(vertices.get(1), vertices.get(0), areaEdgeList, "edge 6"));
edges.add(createAreaEdge(vertices.get(2), vertices.get(1), areaEdgeList, "edge 7"));
edges.add(createAreaEdge(vertices.get(3), vertices.get(2), areaEdgeList, "edge 8"));
edges.add(createAreaEdge(vertices.get(4), vertices.get(3), areaEdgeList, "edge 9"));
edges.add(createAreaEdge(vertices.get(0), vertices.get(4), areaEdgeList, "edge 10"));
Stop stop = Stop.stopForTest("TestStop", 59.13545, 10.22213);
TransitStopVertex stopVertex = new TransitStopVertex(graph, stop, null);
}
Aggregations