use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class TestTurns method testIntersectionVertex.
public void testIntersectionVertex() {
GeometryFactory gf = new GeometryFactory();
LineString geometry = gf.createLineString(new Coordinate[] { new Coordinate(-0.10, 0), new Coordinate(0, 0) });
IntersectionVertex v1 = new IntersectionVertex(null, "v1", -0.10, 0);
IntersectionVertex v2 = new IntersectionVertex(null, "v2", 0, 0);
StreetEdge leftEdge = new StreetEdge(v1, v2, geometry, "morx", 10.0, StreetTraversalPermission.ALL, true);
LineString geometry2 = gf.createLineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(-0.10, 0) });
StreetEdge rightEdge = new StreetEdge(v1, v2, geometry2, "fleem", 10.0, StreetTraversalPermission.ALL, false);
assertEquals(180, Math.abs(leftEdge.getOutAngle() - rightEdge.getOutAngle()));
}
use of org.opentripplanner.routing.edgetype.StreetEdge 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.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class IntersectionVertexTest method edge.
/**
* Create an edge. If twoWay, create two edges (back and forth).
*
* @param vA
* @param vB
* @param length
* @param back true if this is a reverse edge
*/
private StreetEdge edge(StreetVertex vA, StreetVertex vB, double length, boolean back) {
String labelA = vA.getLabel();
String labelB = vB.getLabel();
String name = String.format("%s_%s", labelA, labelB);
Coordinate[] coords = new Coordinate[2];
coords[0] = vA.getCoordinate();
coords[1] = vB.getCoordinate();
LineString geom = GeometryUtils.getGeometryFactory().createLineString(coords);
StreetTraversalPermission perm = StreetTraversalPermission.ALL;
return new StreetEdge(vA, vB, geom, name, length, perm, back);
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class GraphServiceTest method setUp.
@Override
protected void setUp() throws IOException {
// Ensure a dummy disk location exists
basePath = new File("test_graphs");
if (!basePath.exists())
basePath.mkdir();
// Create an empty graph and it's serialized form
emptyGraph = new Graph();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
emptyGraph.save(new ObjectOutputStream(baos));
emptyGraphData = baos.toByteArray();
// Create a small graph with 2 vertices and one edge and it's serialized form
smallGraph = new Graph();
StreetVertex v1 = new IntersectionVertex(smallGraph, "v1", 0, 0);
StreetVertex v2 = new IntersectionVertex(smallGraph, "v2", 0, 0.1);
new StreetEdge(v1, v2, null, "v1v2", 11000, StreetTraversalPermission.PEDESTRIAN, false);
baos = new ByteArrayOutputStream();
smallGraph.save(new ObjectOutputStream(baos));
smallGraphData = baos.toByteArray();
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class StreetSpeedSourceTest method testConcurrency.
@Test
public void testConcurrency() {
Graph g = new Graph();
StreetSpeedSnapshotSource ssss = new StreetSpeedSnapshotSource();
OsmVertex v1 = new OsmVertex(g, "v1", 0, 0, 5l);
OsmVertex v2 = new OsmVertex(g, "v2", 0, 0.01, 6l);
StreetEdge se = new StreetEdge(v1, v2, null, "test", 1000, StreetTraversalPermission.CAR, false);
se.wayId = 10;
Map<Segment, SegmentSpeedSample> ss2 = Maps.newHashMap();
Segment seg = new Segment(10l, 5l, 6l);
ss2.put(seg, getSpeedSample());
StreetSpeedSnapshot ssOrig = new StreetSpeedSnapshot(ss2);
ssss.setSnapshot(ssOrig);
StreetSpeedSnapshot snap = ssss.getSnapshot();
assertEquals(ssOrig, snap);
// should be match
assertFalse(Double.isNaN(snap.getSpeed(se, TraverseMode.CAR, System.currentTimeMillis())));
// should not have changed
assertEquals(snap, ssss.getSnapshot());
Map<Segment, SegmentSpeedSample> ss1 = Maps.newHashMap();
seg = new Segment(10l, 4l, 6l);
ss1.put(seg, getSpeedSample());
StreetSpeedSnapshot ssNew = new StreetSpeedSnapshot(ss1);
ssss.setSnapshot(ssNew);
snap = ssss.getSnapshot();
assertEquals(ssNew, snap);
// should be no match; the segment in the index does not match the street edge
assertTrue(Double.isNaN(snap.getSpeed(se, TraverseMode.CAR, System.currentTimeMillis())));
}
Aggregations