use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.
the class IsoChroneSPTRendererRecursiveGrid method computeInitialPoints.
/**
* Compute a set of initial coordinates for the given SPT
*
* @param spt
* @return
*/
private List<Coordinate> computeInitialPoints(ShortestPathTree spt) {
List<Coordinate> retval = new ArrayList<Coordinate>(spt.getVertexCount());
for (State s : spt.getAllStates()) {
Vertex v = s.getVertex();
// Take only street
if (v instanceof StreetVertex) {
retval.add(v.getCoordinate());
}
}
LOG.debug("Created {} initial points from {} vertexes.", retval.size(), spt.getVertexCount());
return retval;
}
use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.
the class StreetVertexIndexServiceImpl method createHalfLocation.
private static void createHalfLocation(TemporaryStreetLocation base, I18NString name, Coordinate nearestPoint, StreetEdge street, boolean endVertex) {
StreetVertex tov = (StreetVertex) street.getToVertex();
StreetVertex fromv = (StreetVertex) street.getFromVertex();
LineString geometry = street.getGeometry();
P2<LineString> geometries = getGeometry(street, nearestPoint);
double totalGeomLength = geometry.getLength();
double lengthRatioIn = geometries.first.getLength() / totalGeomLength;
double lengthIn = street.getDistance() * lengthRatioIn;
double lengthOut = street.getDistance() * (1 - lengthRatioIn);
if (endVertex) {
TemporaryPartialStreetEdge temporaryPartialStreetEdge = new TemporaryPartialStreetEdge(street, fromv, base, geometries.first, name, lengthIn);
temporaryPartialStreetEdge.setElevationProfile(ElevationUtils.getPartialElevationProfile(street.getElevationProfile(), 0, lengthIn), false);
temporaryPartialStreetEdge.setNoThruTraffic(street.isNoThruTraffic());
temporaryPartialStreetEdge.setStreetClass(street.getStreetClass());
} else {
TemporaryPartialStreetEdge temporaryPartialStreetEdge = new TemporaryPartialStreetEdge(street, base, tov, geometries.second, name, lengthOut);
temporaryPartialStreetEdge.setElevationProfile(ElevationUtils.getPartialElevationProfile(street.getElevationProfile(), lengthIn, lengthIn + lengthOut), false);
temporaryPartialStreetEdge.setStreetClass(street.getStreetClass());
temporaryPartialStreetEdge.setNoThruTraffic(street.isNoThruTraffic());
}
}
use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.
the class PlainStreetEdgeTest method testInAndOutAngles.
@Test
public void testInAndOutAngles() {
// An edge heading straight West
StreetEdge e1 = edge(v1, v2, 1.0, StreetTraversalPermission.ALL);
// Edge has same first and last angle.
assertEquals(90, e1.getInAngle());
assertEquals(90, e1.getOutAngle());
// 2 new ones
StreetVertex u = vertex("test1", 2.0, 1.0);
StreetVertex v = vertex("test2", 2.0, 2.0);
// Second edge, heading straight North
StreetEdge e2 = edge(u, v, 1.0, StreetTraversalPermission.ALL);
// 180 degrees could be expressed as 180 or -180. Our implementation happens to use -180.
assertEquals(180, Math.abs(e2.getInAngle()));
assertEquals(180, Math.abs(e2.getOutAngle()));
}
use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.
the class EdgeTest method testEdgeRemoval.
@Test
public void testEdgeRemoval() {
Graph graph = new Graph();
StreetVertex va = new IntersectionVertex(graph, "A", 10.0, 10.0);
StreetVertex vb = new IntersectionVertex(graph, "B", 10.1, 10.1);
StreetVertex vc = new IntersectionVertex(graph, "C", 10.2, 10.2);
StreetVertex vd = new IntersectionVertex(graph, "D", 10.3, 10.3);
Edge eab = new StreetEdge(va, vb, null, "AB", 10, StreetTraversalPermission.ALL, false);
Edge ebc = new StreetEdge(vb, vc, null, "BC", 10, StreetTraversalPermission.ALL, false);
Edge ecd = new StreetEdge(vc, vd, null, "CD", 10, StreetTraversalPermission.ALL, false);
// remove an edge that is not connected to this vertex
va.removeOutgoing(ecd);
assertEquals(va.getDegreeOut(), 1);
// remove an edge from an edgelist that is empty
vd.removeOutgoing(eab);
assertEquals(vd.getDegreeOut(), 0);
// remove an edge that is actually connected
assertEquals(va.getDegreeOut(), 1);
va.removeOutgoing(eab);
assertEquals(va.getDegreeOut(), 0);
// remove an edge that is actually connected
assertEquals(vb.getDegreeIn(), 1);
assertEquals(vb.getDegreeOut(), 1);
vb.removeIncoming(eab);
assertEquals(vb.getDegreeIn(), 0);
assertEquals(vb.getDegreeOut(), 1);
vb.removeOutgoing(ebc);
assertEquals(vb.getDegreeIn(), 0);
assertEquals(vb.getDegreeOut(), 0);
}
use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.
the class SimpleIsochrone method makePoints.
/**
* @return a map from each vertex to minimum travel time over the course of the day.
*/
private Map<Vertex, Double> makePoints() throws Exception {
rangeCheckParameters();
request = buildRequest();
Router router = otpServer.getRouter(routerId);
Graph graph = router.graph;
// double speed = request.getWalkSpeed();
Coordinate originCoord = request.from.getCoordinate();
if (originCoord == null)
return null;
List<TransitStop> stops = graph.streetIndex.getNearbyTransitStops(originCoord, radiusMeters);
if (stops.isEmpty()) {
LOG.error("No stops found within {} meters.", radiusMeters);
return null;
}
if (shpName == null)
shpName = stops.get(0).getName().split(" ")[0];
StreetVertex origin = new IntersectionVertex(graph, "iso_temp", originCoord.x, originCoord.y);
for (TransitStop stop : stops) {
new StreetTransitLink(origin, stop, false);
LOG.debug("linked to stop {}", stop.getName());
}
request.setRoutingContext(graph, origin, null);
/* Make one request every M minutes over H hours */
int nRequests = (requestTimespanHours * 60) / requestSpacingMinutes;
request.clampInitialWait = (requestSpacingMinutes * 60);
Date date = request.getDateTime();
MinMap<Vertex, Double> points = new MinMap<Vertex, Double>();
for (int r = 0; r < nRequests; r++) {
request.dateTime = date.getTime() / 1000 + r * requestSpacingMinutes * 60;
LOG.debug("date: {} {}", new Date(request.dateTime), request.dateTime);
ShortestPathTree spt = sptService.getShortestPathTree(request, 10);
/* This could even be a good use for a generic SPT merging function */
for (State s : spt.getAllStates()) {
if (stopsOnly && !(s.getVertex() instanceof TransitStop))
continue;
points.putMin(s.getVertex(), (double) (s.getActiveTime()));
}
}
graph.removeVertexAndEdges(origin);
return points;
}
Aggregations