use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class SPTWalker method walk.
/**
* Walk over a SPT. Call a visitor for each visited point.
*/
public void walk(SPTVisitor visitor, double d0) {
int nTotal = 0, nSkippedDupEdge = 0, nSkippedNoGeometry = 0;
Collection<? extends State> allStates = spt.getAllStates();
Set<Vertex> allVertices = new HashSet<Vertex>(spt.getVertexCount());
for (State s : allStates) {
allVertices.add(s.getVertex());
}
Set<Edge> processedEdges = new HashSet<Edge>(allVertices.size());
for (Vertex v : allVertices) {
State s0 = spt.getState(v);
if (s0 == null || !s0.isFinal())
continue;
for (Edge e : s0.getVertex().getIncoming()) {
// Take only street
if (e != null && visitor.accept(e)) {
State s1 = spt.getState(e.getFromVertex());
if (s1 == null || !s1.isFinal())
continue;
if (e.getFromVertex() != null && e.getToVertex() != null) {
// Hack alert: e.hashCode() throw NPE
if (processedEdges.contains(e)) {
nSkippedDupEdge++;
continue;
}
processedEdges.add(e);
}
Vertex vx0 = s0.getVertex();
Vertex vx1 = s1.getVertex();
LineString lineString = e.getGeometry();
if (lineString == null) {
nSkippedNoGeometry++;
continue;
}
// Compute speed along edge
double speedAlongEdge = spt.getOptions().walkSpeed;
if (e instanceof StreetEdge) {
StreetEdge se = (StreetEdge) e;
/*
* Compute effective speed, taking into account end state mode (car, bike,
* walk...) and edge properties (car max speed, slope, etc...)
*/
TraverseMode mode = s0.getNonTransitMode();
speedAlongEdge = se.calculateSpeed(spt.getOptions(), mode, s0.getTimeInMillis());
if (mode != TraverseMode.CAR)
speedAlongEdge = speedAlongEdge * se.getDistance() / se.getSlopeSpeedEffectiveLength();
double avgSpeed = se.getDistance() / Math.abs(s0.getTimeInMillis() - s1.getTimeInMillis()) * 1000;
if (avgSpeed < 1e-10)
avgSpeed = 1e-10;
/*
* We can't go faster than the average speed on the edge. We can go slower
* however, that simply means that one end vertice has a time higher than
* the other end vertice + time to traverse the edge (can happen due to
* max walk clamping).
*/
if (speedAlongEdge > avgSpeed)
speedAlongEdge = avgSpeed;
}
// Length of linestring
double lineStringLen = SphericalDistanceLibrary.fastLength(lineString);
visitor.visit(e, vx0.getCoordinate(), s0, s1, 0.0, lineStringLen, speedAlongEdge);
visitor.visit(e, vx1.getCoordinate(), s0, s1, lineStringLen, 0.0, speedAlongEdge);
nTotal += 2;
Coordinate[] pList = lineString.getCoordinates();
boolean reverse = vx1.getCoordinate().equals(pList[0]);
// Split the linestring in nSteps
if (lineStringLen > d0) {
// Number of steps
int nSteps = (int) Math.floor(lineStringLen / d0) + 1;
// Length of step
double stepLen = lineStringLen / nSteps;
// Distance at start of current seg
double startLen = 0;
// Distance cursor
double curLen = stepLen;
int ns = 1;
for (int i = 0; i < pList.length - 1; i++) {
Coordinate p0 = pList[i];
Coordinate p1 = pList[i + 1];
double segLen = SphericalDistanceLibrary.fastDistance(p0, p1);
while (curLen - startLen < segLen) {
double k = (curLen - startLen) / segLen;
Coordinate p = new Coordinate(p0.x * (1 - k) + p1.x * k, p0.y * (1 - k) + p1.y * k);
visitor.visit(e, p, reverse ? s1 : s0, reverse ? s0 : s1, curLen, lineStringLen - curLen, speedAlongEdge);
nTotal++;
curLen += stepLen;
ns++;
}
startLen += segLen;
if (ns >= nSteps)
break;
}
}
}
}
}
LOG.info("SPTWalker: Generated {} points ({} dup edges, {} no geometry) from {} vertices / {} states.", nTotal, nSkippedDupEdge, nSkippedNoGeometry, allVertices.size(), allStates.size());
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class BikeSafetyEdgeRenderer method renderEdge.
@Override
public boolean renderEdge(Edge e, EdgeVisualAttributes attrs) {
if (e instanceof StreetEdge) {
StreetEdge pse = (StreetEdge) e;
if (pse.getPermission().allows(TraverseMode.BICYCLE)) {
double bikeSafety = pse.getBicycleSafetyFactor();
attrs.color = palette.getColor(bikeSafety);
attrs.label = String.format("%.02f", bikeSafety);
} else {
attrs.color = Color.LIGHT_GRAY;
attrs.label = "no bikes";
}
} else if (e instanceof StreetBikeRentalLink) {
attrs.color = palette.getColor(1.0f);
attrs.label = "link";
} else {
return false;
}
return true;
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class TraversalPermissionsEdgeRenderer method renderEdge.
@Override
public boolean renderEdge(Edge e, EdgeVisualAttributes attrs) {
if (e instanceof StreetEdge) {
StreetEdge pse = (StreetEdge) e;
if (pse.isStairs()) {
attrs.color = STAIRS_COLOR_EDGE;
attrs.label = "stairs";
} else {
attrs.color = getColor(pse.getPermission());
attrs.label = getLabel(pse.getPermission());
}
} else if (e instanceof StreetTransitLink) {
attrs.color = LINK_COLOR_EDGE;
attrs.label = "link";
} else if (e instanceof StreetBikeRentalLink) {
attrs.color = LINK_COLOR_EDGE;
attrs.label = "link";
} else if (e instanceof ParkAndRideLinkEdge) {
attrs.color = LINK_COLOR_EDGE;
attrs.label = "link";
} else {
return false;
}
return true;
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class SimpleStreetSplitter method split.
/**
* Split the street edge at the given fraction
*
* @param edge to be split
* @param ll fraction at which to split the edge
* @param temporarySplit if true this is temporary split at origin/destinations search and only temporary edges vertices are created
* @param endVertex if this is temporary edge this is true if this is end vertex otherwise it doesn't matter
* @return Splitter vertex with added new edges
*/
private SplitterVertex split(StreetEdge edge, LinearLocation ll, boolean temporarySplit, boolean endVertex) {
LineString geometry = edge.getGeometry();
// create the geometries
Coordinate splitPoint = ll.getCoordinate(geometry);
// every edge can be split exactly once, so this is a valid label
SplitterVertex v;
if (temporarySplit) {
v = new TemporarySplitterVertex(graph, "split from " + edge.getId(), splitPoint.x, splitPoint.y, edge, endVertex);
if (edge.isWheelchairAccessible()) {
((TemporarySplitterVertex) v).setWheelchairAccessible(true);
} else {
((TemporarySplitterVertex) v).setWheelchairAccessible(false);
}
} else {
v = new SplitterVertex(graph, "split from " + edge.getId(), splitPoint.x, splitPoint.y, edge);
}
// make the edges
// TODO this is using the StreetEdge implementation of split, which will discard elevation information
// on edges that have it
P2<StreetEdge> edges = edge.split(v, !temporarySplit);
if (destructiveSplitting) {
// update indices of new edges
idx.insert(edges.first.getGeometry(), edges.first);
idx.insert(edges.second.getGeometry(), edges.second);
// (no need to remove original edge, we filter it when it comes out of the index)
// remove original edge from the graph
edge.getToVertex().removeIncoming(edge);
edge.getFromVertex().removeOutgoing(edge);
}
return v;
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class StreetMatcher method createIndex.
STRtree createIndex() {
STRtree edgeIndex = new STRtree();
for (Vertex v : graph.getVertices()) {
for (Edge e : v.getOutgoing()) {
if (e instanceof StreetEdge) {
Envelope envelope;
Geometry geometry = e.getGeometry();
envelope = geometry.getEnvelopeInternal();
edgeIndex.insert(envelope, e);
}
}
}
log.debug("Created index");
return edgeIndex;
}
Aggregations