Search in sources :

Example 11 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class ElevationModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    gridCoverageFactory.setGraph(graph);
    Coverage gridCov = gridCoverageFactory.getGridCoverage();
    // If gridCov is a GridCoverage2D, apply a bilinear interpolator. Otherwise, just use the
    // coverage as is (note: UnifiedGridCoverages created by NEDGridCoverageFactoryImpl handle
    // interpolation internally)
    coverage = (gridCov instanceof GridCoverage2D) ? Interpolator2D.create((GridCoverage2D) gridCov, new InterpolationBilinear()) : gridCov;
    log.info("Setting street elevation profiles from digital elevation model...");
    List<StreetEdge> edgesWithElevation = new ArrayList<StreetEdge>();
    int nProcessed = 0;
    int nTotal = graph.countEdges();
    for (Vertex gv : graph.getVertices()) {
        for (Edge ee : gv.getOutgoing()) {
            if (ee instanceof StreetWithElevationEdge) {
                StreetWithElevationEdge edgeWithElevation = (StreetWithElevationEdge) ee;
                processEdge(graph, edgeWithElevation);
                if (edgeWithElevation.getElevationProfile() != null && !edgeWithElevation.isElevationFlattened()) {
                    edgesWithElevation.add(edgeWithElevation);
                }
                nProcessed += 1;
                if (nProcessed % 50000 == 0) {
                    log.info("set elevation on {}/{} edges", nProcessed, nTotal);
                    double failurePercentage = nPointsOutsideDEM / nPointsEvaluated * 100;
                    if (failurePercentage > 50) {
                        log.warn("Fetching elevation failed at {}/{} points ({}%)", nPointsOutsideDEM, nPointsEvaluated, failurePercentage);
                        log.warn("Elevation is missing at a large number of points. DEM may be for the wrong region. " + "If it is unprojected, perhaps the axes are not in (longitude, latitude) order.");
                    }
                }
            }
        }
    }
    @SuppressWarnings("unchecked") HashMap<Vertex, Double> extraElevation = (HashMap<Vertex, Double>) extra.get(ElevationPoint.class);
    assignMissingElevations(graph, edgesWithElevation, extraElevation);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Coverage(org.opengis.coverage.Coverage) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) ElevationPoint(org.opentripplanner.graph_builder.module.extra_elevation_data.ElevationPoint) StreetWithElevationEdge(org.opentripplanner.routing.edgetype.StreetWithElevationEdge) ElevationPoint(org.opentripplanner.graph_builder.module.extra_elevation_data.ElevationPoint) InterpolationBilinear(javax.media.jai.InterpolationBilinear) StreetWithElevationEdge(org.opentripplanner.routing.edgetype.StreetWithElevationEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 12 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getTransfers.

/**
 * Return the generated transfers a stop in the graph, by stop ID
 */
@GET
@Path("/stops/{stopId}/transfers")
public Response getTransfers(@PathParam("stopId") String stopIdString) {
    Stop stop = index.stopForId.get(GtfsLibrary.convertIdFromString(stopIdString));
    if (stop != null) {
        // get the transfers for the stop
        TransitStop v = index.stopVertexForStop.get(stop);
        Collection<Edge> transfers = Collections2.filter(v.getOutgoing(), new Predicate<Edge>() {

            @Override
            public boolean apply(Edge edge) {
                return edge instanceof SimpleTransfer;
            }
        });
        Collection<Transfer> out = Collections2.transform(transfers, new Function<Edge, Transfer>() {

            @Override
            public Transfer apply(Edge edge) {
                // TODO Auto-generated method stub
                return new Transfer((SimpleTransfer) edge);
            }
        });
        return Response.status(Status.OK).entity(out).build();
    } else {
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    }
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) SimpleTransfer(org.opentripplanner.routing.edgetype.SimpleTransfer) SimpleTransfer(org.opentripplanner.routing.edgetype.SimpleTransfer) Edge(org.opentripplanner.routing.graph.Edge) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 13 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class TransitToTaggedStopsModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    LOG.info("Linking transit stops to tagged bus stops...");
    index = new StreetVertexIndexServiceImpl(graph);
    // iterate over a copy of vertex list because it will be modified
    ArrayList<Vertex> vertices = new ArrayList<>();
    vertices.addAll(graph.getVertices());
    for (TransitStop ts : Iterables.filter(vertices, TransitStop.class)) {
        // if the street is already linked there is no need to linked it again,
        // could happened if using the prune isolated island
        boolean alreadyLinked = false;
        for (Edge e : ts.getOutgoing()) {
            if (e instanceof StreetTransitLink) {
                alreadyLinked = true;
                break;
            }
        }
        if (alreadyLinked)
            continue;
        // entrances
        if (ts.isEntrance() || !ts.hasEntrances()) {
            boolean wheelchairAccessible = ts.hasWheelchairEntrance();
            if (!connectVertexToStop(ts, wheelchairAccessible)) {
                LOG.debug("Could not connect " + ts.getStopCode() + " at " + ts.getCoordinate().toString());
            // LOG.warn(graph.addBuilderAnnotation(new StopUnlinked(ts)));
            }
        }
    }
}
Also used : TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) ArrayList(java.util.ArrayList) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Edge(org.opentripplanner.routing.graph.Edge) StreetVertexIndexServiceImpl(org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl)

Example 14 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class AnalysisUtils method getComponentPolygons.

/**
 * Get polygons covering the components of the graph. The largest component (in terms of number
 * of nodes) will not overlap any other components (it will have holes); the others may overlap
 * each other.
 *
 * @param dateTime
 */
public static List<Geometry> getComponentPolygons(Graph graph, RoutingRequest options, long time) {
    DisjointSet<Vertex> components = getConnectedComponents(graph);
    LinkedListMultimap<Integer, Coordinate> componentCoordinates = LinkedListMultimap.create();
    options.setDummyRoutingContext(graph);
    for (Vertex v : graph.getVertices()) {
        for (Edge e : v.getOutgoing()) {
            State s0 = new State(v, time, options);
            State s1 = e.traverse(s0);
            if (s1 != null) {
                Integer component = components.find(e.getFromVertex());
                Geometry geometry = s1.getBackEdge().getGeometry();
                if (geometry != null) {
                    List<Coordinate> coordinates = new ArrayList<Coordinate>(Arrays.asList(geometry.getCoordinates()));
                    for (int i = 0; i < coordinates.size(); ++i) {
                        Coordinate coordinate = new Coordinate(coordinates.get(i));
                        coordinate.x = Math.round(coordinate.x * PRECISION) / PRECISION;
                        coordinate.y = Math.round(coordinate.y * PRECISION) / PRECISION;
                        coordinates.set(i, coordinate);
                    }
                    componentCoordinates.putAll(component, coordinates);
                }
            }
        }
    }
    // generate convex hull of each component
    List<Geometry> geoms = new ArrayList<Geometry>();
    int mainComponentSize = 0;
    int mainComponentIndex = -1;
    int component = 0;
    for (Integer key : componentCoordinates.keySet()) {
        List<Coordinate> coords = componentCoordinates.get(key);
        Coordinate[] coordArray = new Coordinate[coords.size()];
        ConvexHull hull = new ConvexHull(coords.toArray(coordArray), GeometryUtils.getGeometryFactory());
        Geometry geom = hull.getConvexHull();
        // buffer components which are mere lines so that they do not disappear.
        if (geom instanceof LineString) {
            // ~10 meters
            geom = geom.buffer(0.01);
        } else if (geom instanceof Point) {
            // ~50 meters, so that it shows up
            geom = geom.buffer(0.05);
        }
        geoms.add(geom);
        if (mainComponentSize < coordArray.length) {
            mainComponentIndex = component;
            mainComponentSize = coordArray.length;
        }
        ++component;
    }
    // subtract small components out of main component
    // (small components are permitted to overlap each other)
    Geometry mainComponent = geoms.get(mainComponentIndex);
    for (int i = 0; i < geoms.size(); ++i) {
        Geometry geom = geoms.get(i);
        if (i == mainComponentIndex) {
            continue;
        }
        mainComponent = mainComponent.difference(geom);
    }
    geoms.set(mainComponentIndex, mainComponent);
    return geoms;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ArrayList(java.util.ArrayList) ConvexHull(com.vividsolutions.jts.algorithm.ConvexHull) Point(com.vividsolutions.jts.geom.Point) Point(com.vividsolutions.jts.geom.Point) Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) State(org.opentripplanner.routing.core.State) Edge(org.opentripplanner.routing.graph.Edge)

Example 15 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class PartialStreetEdgeTest method testTraversalOfSubdividedEdge.

@Test
public void testTraversalOfSubdividedEdge() {
    Coordinate nearestPoint = new Coordinate(0.5, 2.0);
    List<StreetEdge> edges = new ArrayList<StreetEdge>();
    edges.add(e2);
    TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(_graph, "middle of e2", new NonLocalizedString("foo"), edges, nearestPoint, true);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(_graph, "middle of e2", new NonLocalizedString("foo"), edges, nearestPoint, false);
    RoutingRequest options = new RoutingRequest();
    options.setMode(TraverseMode.CAR);
    options.setRoutingContext(_graph, v1, v2);
    // All intersections take 10 minutes - we'll notice if one isn't counted.
    double turnDurationSecs = 10.0 * 60.0;
    options.traversalCostModel = (new DummyCostModel(turnDurationSecs));
    options.turnReluctance = (1.0);
    State s0 = new State(options);
    State s1 = e1.traverse(s0);
    State s2 = e2.traverse(s1);
    State s3 = e3.traverse(s2);
    Edge partialE2First = end.getIncoming().iterator().next();
    Edge partialE2Second = start.getOutgoing().iterator().next();
    State partialS0 = new State(options);
    State partialS1 = e1.traverse(partialS0);
    State partialS2A = partialE2First.traverse(partialS1);
    State partialS2B = partialE2Second.traverse(partialS2A);
    State partialS3 = e3.traverse(partialS2B);
    // Should start at the same time.
    assertEquals(s0.getTimeSeconds(), partialS0.getTimeSeconds());
    // Time and cost should be the same up to a rounding difference.
    assertTrue(Math.abs(s3.getTimeSeconds() - partialS3.getTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3.getElapsedTimeSeconds() - partialS3.getElapsedTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3.getWeight() - partialS3.getWeight()) <= 1);
    // All intersections take 0 seconds now.
    options.traversalCostModel = (new DummyCostModel(0.0));
    State s0NoCost = new State(options);
    State s1NoCost = e1.traverse(s0NoCost);
    State s2NoCost = e2.traverse(s1NoCost);
    State s3NoCost = e3.traverse(s2NoCost);
    State partialS0NoCost = new State(options);
    State partialS1NoCost = e1.traverse(partialS0NoCost);
    State partialS2ANoCost = partialE2First.traverse(partialS1NoCost);
    State partialS2BNoCost = partialE2Second.traverse(partialS2ANoCost);
    State partialS3NoCost = e3.traverse(partialS2BNoCost);
    // Time and cost should be the same up to a rounding difference.
    assertTrue(Math.abs(s3NoCost.getTimeSeconds() - partialS3NoCost.getTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3NoCost.getElapsedTimeSeconds() - partialS3NoCost.getElapsedTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3NoCost.getWeight() - partialS3NoCost.getWeight()) <= 1);
    // Difference in duration and weight between now and before should be
    // entirely due to the crossing of 2 intersections at v2 and v3.
    double expectedDifference = 2 * 10 * 60.0;
    double durationDiff = s3.getTimeSeconds() - s3NoCost.getTimeSeconds();
    double partialDurationDiff = partialS3.getTimeSeconds() - partialS3NoCost.getTimeSeconds();
    assertTrue(Math.abs(durationDiff - expectedDifference) <= 1);
    assertTrue(Math.abs(partialDurationDiff - expectedDifference) <= 1);
    // Turn reluctance is 1.0, so weight == duration.
    double weightDiff = s3.getWeight() - s3NoCost.getWeight();
    double partialWeightDiff = partialS3.getWeight() - partialS3NoCost.getWeight();
    assertTrue(Math.abs(weightDiff - expectedDifference) <= 1);
    assertTrue(Math.abs(partialWeightDiff - expectedDifference) <= 1);
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) ArrayList(java.util.ArrayList) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (org.opentripplanner.routing.graph.Edge)113 Vertex (org.opentripplanner.routing.graph.Vertex)61 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)53 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)26 HashSet (java.util.HashSet)23 State (org.opentripplanner.routing.core.State)22 Coordinate (com.vividsolutions.jts.geom.Coordinate)19 Graph (org.opentripplanner.routing.graph.Graph)19 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)18 Test (org.junit.Test)17 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)17 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)17 ArrayList (java.util.ArrayList)16 LineString (com.vividsolutions.jts.geom.LineString)15 GraphPath (org.opentripplanner.routing.spt.GraphPath)15 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)12 PathwayEdge (org.opentripplanner.routing.edgetype.PathwayEdge)11 Geometry (com.vividsolutions.jts.geom.Geometry)9 Stop (org.onebusaway.gtfs.model.Stop)9 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)9