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());
}
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);
}
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)));
}
}
}
}
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;
}
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;
}
Aggregations