Search in sources :

Example 51 with StreetEdge

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()));
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge)

Example 52 with StreetEdge

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>());
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) File(java.io.File) StreetLinkerModule(org.opentripplanner.graph_builder.module.StreetLinkerModule)

Example 53 with StreetEdge

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);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) LineString(com.vividsolutions.jts.geom.LineString)

Example 54 with StreetEdge

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();
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 55 with StreetEdge

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())));
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) OsmVertex(org.opentripplanner.routing.vertextype.OsmVertex) Test(org.junit.Test)

Aggregations

StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)58 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)23 Edge (org.opentripplanner.routing.graph.Edge)22 LineString (com.vividsolutions.jts.geom.LineString)17 Graph (org.opentripplanner.routing.graph.Graph)16 Vertex (org.opentripplanner.routing.graph.Vertex)15 Test (org.junit.Test)13 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)9 HashSet (java.util.HashSet)8 StreetTraversalPermission (org.opentripplanner.routing.edgetype.StreetTraversalPermission)8 State (org.opentripplanner.routing.core.State)7 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)7 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)5 TraverseMode (org.opentripplanner.routing.core.TraverseMode)5 Envelope (com.vividsolutions.jts.geom.Envelope)4 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)4 ArrayList (java.util.ArrayList)4 Before (org.junit.Before)4 StreetTransitLink (org.opentripplanner.routing.edgetype.StreetTransitLink)4