Search in sources :

Example 6 with Vertex

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

the class GraphStatisticsModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    DiscreteDistribution<ConstantQuantifiable<String>> edgeTypeDistribution = new DiscreteDistribution<ConstantQuantifiable<String>>();
    DiscreteDistribution<NumberQuantifiable<Integer>> edgeNameDistribution = new DiscreteDistribution<NumberQuantifiable<Integer>>();
    DiscreteDistribution<NumberQuantifiable<Integer>> geomSizeDistribution = new DiscreteDistribution<NumberQuantifiable<Integer>>();
    DiscreteDistribution<LogQuantifiable<Double>> geomLenDistribution = new DiscreteDistribution<LogQuantifiable<Double>>();
    DiscreteDistribution<ConstantQuantifiable<String>> vertexTypeDistribution = new DiscreteDistribution<ConstantQuantifiable<String>>();
    DiscreteDistribution<NumberQuantifiable<Integer>> vertexNameDistribution = new DiscreteDistribution<NumberQuantifiable<Integer>>();
    DiscreteDistribution<NumberQuantifiable<Integer>> vertexLabelDistribution = new DiscreteDistribution<NumberQuantifiable<Integer>>();
    for (Edge e : graph.getEdges()) {
        edgeTypeDistribution.add(new ConstantQuantifiable<String>(e.getClass().toString()));
        edgeNameDistribution.add(new NumberQuantifiable<Integer>(e.getName() == null ? 0 : e.getName().length()), e.getName());
        if (e.getGeometry() != null) {
            LineString geometry = e.getGeometry();
            geomSizeDistribution.add(new NumberQuantifiable<Integer>(geometry.getNumPoints()));
            double lenMeters = SphericalDistanceLibrary.fastLength(geometry);
            geomLenDistribution.add(new LogQuantifiable<Double>(lenMeters, 5.0));
        }
    }
    for (Vertex v : graph.getVertices()) {
        vertexTypeDistribution.add(new ConstantQuantifiable<String>(v.getClass().toString()));
        vertexNameDistribution.add(new NumberQuantifiable<Integer>(v.getName() == null ? 0 : v.getName().length()), v.getName());
        vertexLabelDistribution.add(new NumberQuantifiable<Integer>(v.getLabel().length()), v.getLabel());
    }
    LOG.info("Geometry size distribution (linear scale, # points):\n" + geomSizeDistribution.toString());
    LOG.info("Geometry length distribution (log scale, meters):\n" + geomLenDistribution.toString());
    LOG.info("Edge type distribution:\n" + edgeTypeDistribution.toString());
    LOG.info("Edge name distribution:\n" + edgeNameDistribution.toString());
    LOG.info("Vertex type distribution:\n" + vertexTypeDistribution.toString());
    LOG.info("Vertex name distribution:\n" + vertexNameDistribution.toString());
    LOG.info("Vertex label distribution:\n" + vertexLabelDistribution.toString());
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) LineString(com.vividsolutions.jts.geom.LineString) LogQuantifiable(org.opentripplanner.util.stats.DiscreteDistribution.LogQuantifiable) NumberQuantifiable(org.opentripplanner.util.stats.DiscreteDistribution.NumberQuantifiable) LineString(com.vividsolutions.jts.geom.LineString) ConstantQuantifiable(org.opentripplanner.util.stats.DiscreteDistribution.ConstantQuantifiable) Edge(org.opentripplanner.routing.graph.Edge) DiscreteDistribution(org.opentripplanner.util.stats.DiscreteDistribution)

Example 7 with Vertex

use of org.opentripplanner.routing.graph.Vertex 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 8 with Vertex

use of org.opentripplanner.routing.graph.Vertex 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 9 with Vertex

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

the class TransitToTaggedStopsModule method connectVertexToStop.

private boolean connectVertexToStop(TransitStop ts, boolean wheelchairAccessible) {
    String stopCode = ts.getStopCode();
    if (stopCode == null) {
        return false;
    }
    Envelope envelope = new Envelope(ts.getCoordinate());
    double xscale = Math.cos(ts.getCoordinate().y * Math.PI / 180);
    envelope.expandBy(searchRadiusLat / xscale, searchRadiusLat);
    Collection<Vertex> vertices = index.getVerticesForEnvelope(envelope);
    // in their ref= tag that matches the GTFS stop code of this TransitStop.
    for (Vertex v : vertices) {
        if (!(v instanceof TransitStopStreetVertex)) {
            continue;
        }
        TransitStopStreetVertex tsv = (TransitStopStreetVertex) v;
        // Only use stop codes for linking TODO: find better method to connect stops without stop code
        if (tsv.stopCode != null && tsv.stopCode.equals(stopCode)) {
            new StreetTransitLink(ts, tsv, wheelchairAccessible);
            new StreetTransitLink(tsv, ts, wheelchairAccessible);
            LOG.debug("Connected " + ts.toString() + " to " + tsv.getLabel());
            return true;
        }
    }
    return false;
}
Also used : TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 10 with Vertex

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

the class PortlandCustomNamer method nameAccordingToDestination.

private String nameAccordingToDestination(Graph graph, StreetEdge e, int maxDepth) {
    if (maxDepth == 0) {
        return null;
    }
    Vertex toVertex = e.getToVertex();
    for (StreetEdge out : Iterables.filter(toVertex.getOutgoing(), StreetEdge.class)) {
        if (out.hasBogusName()) {
            String name = nameAccordingToDestination(graph, out, maxDepth - 1);
            if (name == null) {
                continue;
            }
            e.setName(new NonLocalizedString(name));
            return name;
        } else {
            String name = out.getName();
            e.setName(new NonLocalizedString(name));
            return name;
        }
    }
    return null;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) NonLocalizedString(org.opentripplanner.util.NonLocalizedString)

Aggregations

Vertex (org.opentripplanner.routing.graph.Vertex)143 Edge (org.opentripplanner.routing.graph.Edge)63 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)45 GraphPath (org.opentripplanner.routing.spt.GraphPath)39 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)35 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)34 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)32 Graph (org.opentripplanner.routing.graph.Graph)29 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)28 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)24 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 State (org.opentripplanner.routing.core.State)20 Stop (org.onebusaway.gtfs.model.Stop)18 LineString (com.vividsolutions.jts.geom.LineString)16 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 Trip (org.onebusaway.gtfs.model.Trip)12 Envelope (com.vividsolutions.jts.geom.Envelope)11