Search in sources :

Example 1 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class IsoChroneSPTRendererRecursiveGrid method computeInitialPoints.

/**
 * Compute a set of initial coordinates for the given SPT
 *
 * @param spt
 * @return
 */
private List<Coordinate> computeInitialPoints(ShortestPathTree spt) {
    List<Coordinate> retval = new ArrayList<Coordinate>(spt.getVertexCount());
    for (State s : spt.getAllStates()) {
        Vertex v = s.getVertex();
        // Take only street
        if (v instanceof StreetVertex) {
            retval.add(v.getCoordinate());
        }
    }
    LOG.debug("Created {} initial points from {} vertexes.", retval.size(), spt.getVertexCount());
    return retval;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) ArrayList(java.util.ArrayList) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 2 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class StreetVertexIndexServiceImpl method createHalfLocation.

private static void createHalfLocation(TemporaryStreetLocation base, I18NString name, Coordinate nearestPoint, StreetEdge street, boolean endVertex) {
    StreetVertex tov = (StreetVertex) street.getToVertex();
    StreetVertex fromv = (StreetVertex) street.getFromVertex();
    LineString geometry = street.getGeometry();
    P2<LineString> geometries = getGeometry(street, nearestPoint);
    double totalGeomLength = geometry.getLength();
    double lengthRatioIn = geometries.first.getLength() / totalGeomLength;
    double lengthIn = street.getDistance() * lengthRatioIn;
    double lengthOut = street.getDistance() * (1 - lengthRatioIn);
    if (endVertex) {
        TemporaryPartialStreetEdge temporaryPartialStreetEdge = new TemporaryPartialStreetEdge(street, fromv, base, geometries.first, name, lengthIn);
        temporaryPartialStreetEdge.setElevationProfile(ElevationUtils.getPartialElevationProfile(street.getElevationProfile(), 0, lengthIn), false);
        temporaryPartialStreetEdge.setNoThruTraffic(street.isNoThruTraffic());
        temporaryPartialStreetEdge.setStreetClass(street.getStreetClass());
    } else {
        TemporaryPartialStreetEdge temporaryPartialStreetEdge = new TemporaryPartialStreetEdge(street, base, tov, geometries.second, name, lengthOut);
        temporaryPartialStreetEdge.setElevationProfile(ElevationUtils.getPartialElevationProfile(street.getElevationProfile(), lengthIn, lengthIn + lengthOut), false);
        temporaryPartialStreetEdge.setStreetClass(street.getStreetClass());
        temporaryPartialStreetEdge.setNoThruTraffic(street.isNoThruTraffic());
    }
}
Also used : LineString(com.vividsolutions.jts.geom.LineString) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 3 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class PlainStreetEdgeTest method testInAndOutAngles.

@Test
public void testInAndOutAngles() {
    // An edge heading straight West
    StreetEdge e1 = edge(v1, v2, 1.0, StreetTraversalPermission.ALL);
    // Edge has same first and last angle.
    assertEquals(90, e1.getInAngle());
    assertEquals(90, e1.getOutAngle());
    // 2 new ones
    StreetVertex u = vertex("test1", 2.0, 1.0);
    StreetVertex v = vertex("test2", 2.0, 2.0);
    // Second edge, heading straight North
    StreetEdge e2 = edge(u, v, 1.0, StreetTraversalPermission.ALL);
    // 180 degrees could be expressed as 180 or -180. Our implementation happens to use -180.
    assertEquals(180, Math.abs(e2.getInAngle()));
    assertEquals(180, Math.abs(e2.getOutAngle()));
}
Also used : StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Test(org.junit.Test)

Example 4 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class EdgeTest method testEdgeRemoval.

@Test
public void testEdgeRemoval() {
    Graph graph = new Graph();
    StreetVertex va = new IntersectionVertex(graph, "A", 10.0, 10.0);
    StreetVertex vb = new IntersectionVertex(graph, "B", 10.1, 10.1);
    StreetVertex vc = new IntersectionVertex(graph, "C", 10.2, 10.2);
    StreetVertex vd = new IntersectionVertex(graph, "D", 10.3, 10.3);
    Edge eab = new StreetEdge(va, vb, null, "AB", 10, StreetTraversalPermission.ALL, false);
    Edge ebc = new StreetEdge(vb, vc, null, "BC", 10, StreetTraversalPermission.ALL, false);
    Edge ecd = new StreetEdge(vc, vd, null, "CD", 10, StreetTraversalPermission.ALL, false);
    // remove an edge that is not connected to this vertex
    va.removeOutgoing(ecd);
    assertEquals(va.getDegreeOut(), 1);
    // remove an edge from an edgelist that is empty
    vd.removeOutgoing(eab);
    assertEquals(vd.getDegreeOut(), 0);
    // remove an edge that is actually connected
    assertEquals(va.getDegreeOut(), 1);
    va.removeOutgoing(eab);
    assertEquals(va.getDegreeOut(), 0);
    // remove an edge that is actually connected
    assertEquals(vb.getDegreeIn(), 1);
    assertEquals(vb.getDegreeOut(), 1);
    vb.removeIncoming(eab);
    assertEquals(vb.getDegreeIn(), 0);
    assertEquals(vb.getDegreeOut(), 1);
    vb.removeOutgoing(ebc);
    assertEquals(vb.getDegreeIn(), 0);
    assertEquals(vb.getDegreeOut(), 0);
}
Also used : IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Test(org.junit.Test)

Example 5 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class SimpleIsochrone method makePoints.

/**
 * @return a map from each vertex to minimum travel time over the course of the day.
 */
private Map<Vertex, Double> makePoints() throws Exception {
    rangeCheckParameters();
    request = buildRequest();
    Router router = otpServer.getRouter(routerId);
    Graph graph = router.graph;
    // double speed = request.getWalkSpeed();
    Coordinate originCoord = request.from.getCoordinate();
    if (originCoord == null)
        return null;
    List<TransitStop> stops = graph.streetIndex.getNearbyTransitStops(originCoord, radiusMeters);
    if (stops.isEmpty()) {
        LOG.error("No stops found within {} meters.", radiusMeters);
        return null;
    }
    if (shpName == null)
        shpName = stops.get(0).getName().split(" ")[0];
    StreetVertex origin = new IntersectionVertex(graph, "iso_temp", originCoord.x, originCoord.y);
    for (TransitStop stop : stops) {
        new StreetTransitLink(origin, stop, false);
        LOG.debug("linked to stop {}", stop.getName());
    }
    request.setRoutingContext(graph, origin, null);
    /* Make one request every M minutes over H hours */
    int nRequests = (requestTimespanHours * 60) / requestSpacingMinutes;
    request.clampInitialWait = (requestSpacingMinutes * 60);
    Date date = request.getDateTime();
    MinMap<Vertex, Double> points = new MinMap<Vertex, Double>();
    for (int r = 0; r < nRequests; r++) {
        request.dateTime = date.getTime() / 1000 + r * requestSpacingMinutes * 60;
        LOG.debug("date: {} {}", new Date(request.dateTime), request.dateTime);
        ShortestPathTree spt = sptService.getShortestPathTree(request, 10);
        /* This could even be a good use for a generic SPT merging function */
        for (State s : spt.getAllStates()) {
            if (stopsOnly && !(s.getVertex() instanceof TransitStop))
                continue;
            points.putMin(s.getVertex(), (double) (s.getActiveTime()));
        }
    }
    graph.removeVertexAndEdges(origin);
    return points;
}
Also used : StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Router(org.opentripplanner.standalone.Router) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Point(com.vividsolutions.jts.geom.Point) Date(java.util.Date) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Aggregations

StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)18 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)8 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)8 Graph (org.opentripplanner.routing.graph.Graph)7 Vertex (org.opentripplanner.routing.graph.Vertex)5 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 LineString (com.vividsolutions.jts.geom.LineString)4 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)4 State (org.opentripplanner.routing.core.State)4 Edge (org.opentripplanner.routing.graph.Edge)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 File (java.io.File)2 Before (org.junit.Before)2 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)2 FreeEdge (org.opentripplanner.routing.edgetype.FreeEdge)2 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)2 SplitterVertex (org.opentripplanner.routing.vertextype.SplitterVertex)2 Envelope (com.vividsolutions.jts.geom.Envelope)1