Search in sources :

Example 11 with StreetEdge

use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.

the class StreetVertex method getIntersectionName.

/**
 * Creates intersection name out of all outgoing names
 *
 * This can be:
 *  - name of the street if it is only 1
 *  - unnamedStreed (localized in requested language) if it doesn't have a name
 *  - corner of 0 and 1 (localized corner of zero and first street in the corner)
 *
 * @param locale Wanted locale
 * @return already localized street names and non-localized corner of x and unnamedStreet
 */
public I18NString getIntersectionName(Locale locale) {
    I18NString calculatedName = null;
    // generate names for corners when no name was given
    Set<String> uniqueNameSet = new HashSet<String>();
    for (Edge e : getOutgoing()) {
        if (e instanceof StreetEdge) {
            uniqueNameSet.add(e.getName(locale));
        }
    }
    List<String> uniqueNames = new ArrayList<String>(uniqueNameSet);
    if (uniqueNames.size() > 1) {
        calculatedName = new LocalizedString("corner", new String[] { uniqueNames.get(0), uniqueNames.get(1) });
    } else if (uniqueNames.size() == 1) {
        calculatedName = new NonLocalizedString(uniqueNames.get(0));
    } else {
        calculatedName = new LocalizedString("unnamedStreet", (String[]) null);
    }
    return calculatedName;
}
Also used : I18NString(org.opentripplanner.util.I18NString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) I18NString(org.opentripplanner.util.I18NString) LocalizedString(org.opentripplanner.util.LocalizedString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) LocalizedString(org.opentripplanner.util.LocalizedString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 12 with StreetEdge

use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.

the class LinkingTest method testSplitting.

/**
 * Ensure that splitting edges yields edges that are identical in length for forward and back edges.
 * StreetEdges have lengths expressed internally in mm, and we want to be sure that not only do they
 * sum to the same values but also that they
 */
@Test
public void testSplitting() {
    GeometryFactory gf = GeometryUtils.getGeometryFactory();
    double x = -122.123;
    double y = 37.363;
    for (double delta = 0; delta <= 2; delta += 0.005) {
        StreetVertex v0 = new IntersectionVertex(null, "zero", x, y);
        StreetVertex v1 = new IntersectionVertex(null, "one", x + delta, y + delta);
        LineString geom = gf.createLineString(new Coordinate[] { v0.getCoordinate(), v1.getCoordinate() });
        double dist = SphericalDistanceLibrary.distance(v0.getCoordinate(), v1.getCoordinate());
        StreetEdge s0 = new StreetEdge(v0, v1, geom, "test", dist, StreetTraversalPermission.ALL, false);
        StreetEdge s1 = new StreetEdge(v1, v0, (LineString) geom.reverse(), "back", dist, StreetTraversalPermission.ALL, true);
        // split it but not too close to the end
        double splitVal = Math.random() * 0.95 + 0.025;
        SplitterVertex sv0 = new SplitterVertex(null, "split", x + delta * splitVal, y + delta * splitVal, s0);
        SplitterVertex sv1 = new SplitterVertex(null, "split", x + delta * splitVal, y + delta * splitVal, s1);
        P2<StreetEdge> sp0 = s0.split(sv0, true);
        P2<StreetEdge> sp1 = s1.split(sv1, true);
        // distances expressed internally in mm so this epsilon is plenty good enough to ensure that they
        // have the same values
        assertEquals(sp0.first.getDistance(), sp1.second.getDistance(), 0.0000001);
        assertEquals(sp0.second.getDistance(), sp1.first.getDistance(), 0.0000001);
        assertFalse(sp0.first.isBack());
        assertFalse(sp0.second.isBack());
        assertTrue(sp1.first.isBack());
        assertTrue(sp1.second.isBack());
    }
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) LineString(com.vividsolutions.jts.geom.LineString) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) SplitterVertex(org.opentripplanner.routing.vertextype.SplitterVertex) Test(org.junit.Test)

Example 13 with StreetEdge

use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method setUp.

@Before
public void setUp() {
    graph = new Graph();
    // a 0.1 degree x 0.1 degree square
    tl = new IntersectionVertex(graph, "tl", -74.01, 40.01);
    tr = new IntersectionVertex(graph, "tr", -74.0, 40.01);
    bl = new IntersectionVertex(graph, "bl", -74.01, 40.0);
    br = new IntersectionVertex(graph, "br", -74.00, 40.0);
    top = new StreetEdge(tl, tr, GeometryUtils.makeLineString(-74.01, 40.01, -74.0, 40.01), "top", 1500, StreetTraversalPermission.ALL, false);
    bottom = new StreetEdge(br, bl, GeometryUtils.makeLineString(-74.01, 40.0, -74.0, 40.0), "bottom", 1500, StreetTraversalPermission.ALL, false);
    left = new StreetEdge(bl, tl, GeometryUtils.makeLineString(-74.01, 40.0, -74.01, 40.01), "left", 1500, StreetTraversalPermission.ALL, false);
    right = new StreetEdge(br, tr, GeometryUtils.makeLineString(-74.0, 40.0, -74.0, 40.01), "right", 1500, StreetTraversalPermission.PEDESTRIAN, false);
    @SuppressWarnings("unused") StreetEdge topBack = new StreetEdge(tr, tl, (LineString) top.getGeometry().reverse(), "topBack", 1500, StreetTraversalPermission.ALL, true);
    @SuppressWarnings("unused") StreetEdge bottomBack = new StreetEdge(br, bl, (LineString) bottom.getGeometry().reverse(), "bottomBack", 1500, StreetTraversalPermission.ALL, true);
    leftBack = new StreetEdge(tl, bl, (LineString) left.getGeometry().reverse(), "leftBack", 1500, StreetTraversalPermission.ALL, true);
    rightBack = new StreetEdge(tr, br, (LineString) right.getGeometry().reverse(), "rightBack", 1500, StreetTraversalPermission.ALL, true);
    Stop s1 = new Stop();
    s1.setName("transitVertex 1");
    s1.setLon(-74.005);
    s1.setLat(40.0099999);
    s1.setId(new AgencyAndId("A", "fleem station"));
    Stop s2 = new Stop();
    s2.setName("transitVertex 2");
    s2.setLon(-74.002);
    s2.setLat(40.0099999);
    s2.setId(new AgencyAndId("A", "morx station"));
    station1 = new TransitStop(graph, s1);
    station2 = new TransitStop(graph, s2);
    station1.addMode(TraverseMode.RAIL);
    station2.addMode(TraverseMode.RAIL);
    graph.rebuildVertexAndEdgeIndices();
    // Linkers aren't run otherwise in testNetworkLinker
    graph.hasStreets = true;
    graph.hasTransit = true;
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) LineString(com.vividsolutions.jts.geom.LineString) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Before(org.junit.Before)

Example 14 with StreetEdge

use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.

the class SimpleTraversalCostModelTest method testInferredFreeFlowing.

@Test
public void testInferredFreeFlowing() {
    // 3 points on a roughly on line
    Coordinate a = new Coordinate(-73.990989, 40.750167);
    Coordinate b = new Coordinate(-73.988049, 40.749094);
    Coordinate c = new Coordinate(-73.984981, 40.747761);
    // A vertex for each. No light.
    IntersectionVertex u = vertex("from_v", a, false);
    IntersectionVertex v = vertex("intersection", b, false);
    IntersectionVertex w = vertex("to_v", c, false);
    // Two edges - will infer that the vertex is free-flowing since there is no light.
    StreetEdge fromEdge = edge(u, v, 1.0, false);
    StreetEdge toEdge = edge(v, w, 1.0, false);
    float fromSpeed = 1.0f;
    float toSpeed = 1.0f;
    TraverseMode mode = TraverseMode.CAR;
    double traversalCost = costModel.computeTraversalCost(v, fromEdge, toEdge, mode, options, fromSpeed, toSpeed);
    // Vertex is free-flowing so cost should be 0.0.
    assertEquals(0.0, traversalCost, 0.0);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Test(org.junit.Test)

Example 15 with StreetEdge

use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.

the class SimpleTraversalCostModelTest method testTurnDirectionChecking.

@Test
public void testTurnDirectionChecking() {
    // 3 points on a roughly on line
    Coordinate a = new Coordinate(-73.990989, 40.750167);
    Coordinate b = new Coordinate(-73.988049, 40.749094);
    Coordinate c = new Coordinate(-73.984981, 40.747761);
    // A vertex for each. No light.
    IntersectionVertex u = vertex("from_v", a, false);
    IntersectionVertex v = vertex("intersection", b, false);
    IntersectionVertex w = vertex("to_v", c, false);
    // Two edges.
    StreetEdge fromEdge = edge(u, v, 1.0, false);
    StreetEdge toEdge = edge(v, w, 1.0, false);
    int turnAngle = costModel.calculateTurnAngle(fromEdge, toEdge, options);
    assertFalse(costModel.isRightTurn(turnAngle));
    assertFalse(costModel.isLeftTurn(turnAngle));
// AKA is a straight ahead.
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) 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