use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class GraphVisualizer method reactToEdgeSelection.
private void reactToEdgeSelection(Edge selected, boolean outgoing) {
if (selected == null) {
return;
}
showGraph.highlightEdge(selected);
/* for turns, highlight the outgoing street's ends */
if (selected instanceof StreetEdge) {
List<Vertex> vertices = new ArrayList<Vertex>();
List<Edge> edges = new ArrayList<Edge>();
Vertex tov = selected.getToVertex();
for (Edge og : tov.getOutgoing()) {
if (og instanceof StreetEdge) {
edges.add(og);
vertices.add(og.getToVertex());
break;
}
}
Vertex fromv = selected.getFromVertex();
for (Edge ic : fromv.getIncoming()) {
if (ic instanceof StreetEdge) {
edges.add(ic);
vertices.add(ic.getFromVertex());
break;
}
}
// showGraph.setHighlightedVertices(vertices);
showGraph.setHighlightedEdges(edges);
}
/* add the connected vertices to the list of vertices */
VertexList nearbyModel = (VertexList) nearbyVertices.getModel();
List<Vertex> vertices = nearbyModel.selected;
Vertex v;
if (outgoing) {
v = selected.getToVertex();
} else {
v = selected.getFromVertex();
}
if (!vertices.contains(v)) {
vertices.add(v);
nearbyModel = new VertexList(vertices);
// this should just be an event, but for
nearbyVertices.setModel(nearbyModel);
// some reason, JList doesn't implement
// the right event.
}
/* set up metadata tab */
metadataModel.clear();
getMetadata(selected);
// fromv
Vertex fromv = selected.getFromVertex();
getMetadata(fromv);
if (selected instanceof StreetEdge) {
// TODO ElevationProfileSegment do not exist anymore
// getMetadata(((StreetEdge) selected).getElevationProfileSegment());
}
metadataList.revalidate();
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class ShowGraph method findVisibleElements.
@SuppressWarnings("unchecked")
private synchronized void findVisibleElements() {
visibleVertices = (List<Vertex>) vertexIndex.query(modelBounds);
visibleStreetEdges.clear();
visibleLinkEdges.clear();
visibleTransitEdges.clear();
for (Edge de : (Iterable<Edge>) edgeIndex.query(modelBounds)) {
if (de instanceof PatternEdge) {
visibleTransitEdges.add(de);
} else if (de instanceof PathwayEdge || de instanceof StreetTransitLink || de instanceof SimpleTransfer) {
visibleLinkEdges.add(de);
} else if (de instanceof StreetEdge) {
visibleStreetEdges.add(de);
}
}
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class TestOpenStreetMapGraphBuilder method testBuildGraphDetailed.
/**
* Detailed testing of OSM graph building using a very small chunk of NYC (SOHO-ish).
* @throws Exception
*/
@Test
public void testBuildGraphDetailed() throws Exception {
Graph gg = new Graph();
OpenStreetMapModule loader = new OpenStreetMapModule();
loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
File file = new File(URLDecoder.decode(getClass().getResource("NYC_small.osm.gz").getFile(), "UTF-8"));
provider.setPath(file);
loader.setProvider(provider);
loader.buildGraph(gg, extra);
// These vertices are labeled in the OSM file as having traffic lights.
IntersectionVertex iv1 = (IntersectionVertex) gg.getVertex("osm:node:1919595918");
IntersectionVertex iv2 = (IntersectionVertex) gg.getVertex("osm:node:42442273");
IntersectionVertex iv3 = (IntersectionVertex) gg.getVertex("osm:node:1919595927");
IntersectionVertex iv4 = (IntersectionVertex) gg.getVertex("osm:node:42452026");
assertTrue(iv1.trafficLight);
assertTrue(iv2.trafficLight);
assertTrue(iv3.trafficLight);
assertTrue(iv4.trafficLight);
// These are not.
IntersectionVertex iv5 = (IntersectionVertex) gg.getVertex("osm:node:42435485");
IntersectionVertex iv6 = (IntersectionVertex) gg.getVertex("osm:node:42439335");
IntersectionVertex iv7 = (IntersectionVertex) gg.getVertex("osm:node:42436761");
IntersectionVertex iv8 = (IntersectionVertex) gg.getVertex("osm:node:42442291");
assertFalse(iv5.trafficLight);
assertFalse(iv6.trafficLight);
assertFalse(iv7.trafficLight);
assertFalse(iv8.trafficLight);
Set<P2<Integer>> edgeEndpoints = new HashSet<P2<Integer>>();
for (StreetEdge se : gg.getStreetEdges()) {
P2<Integer> endpoints = new P2<Integer>(se.getFromVertex().getIndex(), se.getToVertex().getIndex());
// Check that we don't get any duplicate edges on this small graph.
if (edgeEndpoints.contains(endpoints)) {
assertFalse(true);
}
edgeEndpoints.add(endpoints);
}
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class SIsochrone method distanceToMoveInRemainingTime.
/**
* Calculates what distance can be traveled with the remaining time and given speeds. For car use the speed limit is taken from the edge itself.
* Slopes are accounted for when walking and biking. A minimal slope of 0.06 (6m/100m) is necessary.
*
* @param maxTime in sec, the time we have left
* @param fromTime in sec, the time when we enter the edge
* @param traverseTime in sec, original edge traverse time needed to adjust the speed based calculation to slope effects
* @param userSpeed in m/sec, dependent on traversal mode
* @param edge the edge itself (used to the get the speed in car mode)
* @param usesCar if we traverse the edge in car mode
* @param hasUshape if know, indicate if the edge has a u-shape
* @return the distance in meter that can be moved until maxTime
*/
double distanceToMoveInRemainingTime(long maxTime, long fromTime, double traverseTime, double userSpeed, Edge edge, boolean usesCar, boolean hasUshape) {
boolean isTooFast = false;
String msg = "";
// this may be wrong for u-shapes
double originalTravelSpeed = edge.getDistance() / traverseTime;
if (originalTravelSpeed < userSpeed) {
// we may have slope effects
if (edge instanceof StreetEdge) {
StreetEdge pe = (StreetEdge) edge;
double maxSlope = pe.getMaxSlope();
// if we are over the slope limit, then we should use the slower speed
if (maxSlope > 0.06) {
// limit 6m/100m = 3.4 degree
userSpeed = originalTravelSpeed;
}
}
} else {
// in this case we may have a u-shape, or the user speeds are too small, or something else.
double vdiff = Math.abs(originalTravelSpeed - userSpeed);
double vDiffPercent = vdiff / (userSpeed / 100.0);
if (vDiffPercent > 20) {
isTooFast = true;
// [sstein Dec 2012]: Note, it seems like most of these edges are indeed of u-shape type,
// i.e. small roads that come from and return from (the same) main road
msg = "v_traversed is much faster than (allowed) v_user, edgeName: " + edge.getName() + ", >>> (in m/s): v_traversed=" + (int) Math.floor(originalTravelSpeed) + ", v_maxUser=" + (int) Math.floor(userSpeed);
if (hasUshape) {
msg = msg + ", known u-shape, ";
}
if ((usesCar == false) && (hasUshape == false)) {
this.tooFastTraversedEdgeGeoms.add(edge.getGeometry());
LOG.debug(msg);
}
// otherwise we print msg below
}
}
// correct speed for car use, as each road has its speed limits
if (usesCar) {
if (edge instanceof StreetEdge) {
StreetEdge pe = (StreetEdge) edge;
userSpeed = pe.getCarSpeed();
// we need to check again if the originalTravelSpeed is faster
if ((isTooFast == true) && (originalTravelSpeed > userSpeed) && (hasUshape == false)) {
this.tooFastTraversedEdgeGeoms.add(edge.getGeometry());
LOG.debug(msg + "; setting v_PlainStreetEdge=" + (int) Math.floor(userSpeed));
}
}
}
// finally calculate how far we can travel with the remaining time
long timeMissing = maxTime - fromTime;
double distanceToWalkInTimeMissing = timeMissing * userSpeed;
return distanceToWalkInTimeMissing;
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class NearbyStopFinder method stopAtDistanceForState.
/**
* Given a State at a TransitStop, bundle the TransitStop together with information about how far away it is
* and the geometry of the path leading up to the given State.
*
* TODO this should probably be merged with similar classes in Profile routing.
*/
public static StopAtDistance stopAtDistanceForState(State state) {
double distance = 0.0;
GraphPath graphPath = new GraphPath(state, false);
CoordinateArrayListSequence coordinates = new CoordinateArrayListSequence();
List<Edge> edges = new ArrayList<>();
for (Edge edge : graphPath.edges) {
if (edge instanceof StreetEdge) {
LineString geometry = edge.getGeometry();
if (geometry != null) {
if (coordinates.size() == 0) {
coordinates.extend(geometry.getCoordinates());
} else {
coordinates.extend(geometry.getCoordinates(), 1);
}
}
distance += edge.getDistance();
}
edges.add(edge);
}
if (coordinates.size() < 2) {
// Otherwise the walk step generator breaks.
ArrayList<Coordinate> coordinateList = new ArrayList<Coordinate>(2);
coordinateList.add(graphPath.states.get(1).getVertex().getCoordinate());
State lastState = graphPath.states.getLast().getBackState();
coordinateList.add(lastState.getVertex().getCoordinate());
coordinates = new CoordinateArrayListSequence(coordinateList);
}
StopAtDistance sd = new StopAtDistance((TransitStop) state.getVertex(), distance);
sd.geom = geometryFactory.createLineString(new PackedCoordinateSequence.Double(coordinates.toCoordinateArray()));
sd.edges = edges;
return sd;
}
Aggregations