use of org.opentripplanner.analyst.TimeSurface in project OpenTripPlanner by opentripplanner.
the class SurfaceResource method getIndicator.
/**
* Evaluate a surface at all the points in a PointSet.
* This sends back a ResultSet serialized as JSON.
* Normally we return historgrams with the number of points reached (in field 'counts') and the number of
* opportunities reached (i.e. the sum of the magnitudes of all points reached) in each one-minute bin of travel
* time.
* @param detail if true, include the travel time to every point in the pointset (which is in fact an ordered list)
*/
@GET
@Path("/{surfaceId}/indicator")
public Response getIndicator(@PathParam("surfaceId") Integer surfaceId, @QueryParam("targets") String targetPointSetId, @QueryParam("origins") String originPointSetId, @QueryParam("detail") boolean detail) {
final TimeSurface surf = otpServer.surfaceCache.get(surfaceId);
if (surf == null)
return badRequest("Invalid TimeSurface ID.");
final PointSet pset = otpServer.pointSetCache.get(targetPointSetId);
if (pset == null)
return badRequest("Missing or invalid target PointSet ID.");
Router router = otpServer.getRouter(surf.routerId);
// TODO cache this sampleset
SampleSet samples = pset.getSampleSet(router.graph);
final ResultSet indicator = new ResultSet(samples, surf, detail, detail);
if (indicator == null)
return badServer("Could not compute indicator as requested.");
return Response.ok().entity(new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
indicator.writeJson(output);
}
}).build();
}
use of org.opentripplanner.analyst.TimeSurface in project OpenTripPlanner by opentripplanner.
the class SurfaceResource method tileGet.
@Path("/{surfaceId}/isotiles/{z}/{x}/{y}.png")
@GET
@Produces("image/png")
public Response tileGet(@PathParam("surfaceId") Integer surfaceId, @PathParam("x") int x, @PathParam("y") int y, @PathParam("z") int z) throws Exception {
Envelope2D env = SlippyTile.tile2Envelope(x, y, z);
TimeSurface surfA = otpServer.surfaceCache.get(surfaceId);
if (surfA == null)
return badRequest("Unrecognized surface ID.");
TileRequest tileRequest = new TileRequest(env, 256, 256);
MIMEImageFormat imageFormat = new MIMEImageFormat("image/png");
RenderRequest renderRequest = new RenderRequest(imageFormat, Layer.TRAVELTIME, Style.COLOR30, true, false);
// TODO why can't the renderer be static?
Router router = otpServer.getRouter(surfA.routerId);
return router.renderer.getResponse(tileRequest, surfA, null, renderRequest);
}
use of org.opentripplanner.analyst.TimeSurface in project OpenTripPlanner by opentripplanner.
the class SurfaceResource method getIsochrone.
/**
* Create vector isochrones for a surface.
*/
@GET
@Path("/{surfaceId}/isochrone")
public Response getIsochrone(@PathParam("surfaceId") Integer surfaceId, @QueryParam("spacing") int spacing, @QueryParam("nMax") @DefaultValue("1") int nMax) {
final TimeSurface surf = otpServer.surfaceCache.get(surfaceId);
if (surf == null)
return badRequest("Invalid TimeSurface ID.");
if (spacing < 1)
spacing = 30;
List<IsochroneData> isochrones = getIsochronesAccumulative(surf, spacing, nMax);
// NOTE that cutoffMinutes in the surface must be properly set for the following call to work
final FeatureCollection fc = LIsochrone.makeContourFeatures(isochrones);
return Response.ok().entity(new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException {
FeatureJSON fj = new FeatureJSON();
fj.writeFeatureCollection(fc, output);
}
}).build();
}
use of org.opentripplanner.analyst.TimeSurface in project OpenTripPlanner by opentripplanner.
the class ProfileRouter method makeSurfaces.
private void makeSurfaces() {
LOG.info("Propagating from transit stops to the street network...");
// A map to store the travel time to each vertex
TimeSurface minSurface = new TimeSurface(this);
TimeSurface avgSurface = new TimeSurface(this);
TimeSurface maxSurface = new TimeSurface(this);
// Grab a cached map of distances to street intersections from each transit stop
StopTreeCache stopTreeCache = graph.index.getStopTreeCache();
// Iterate over all nondominated rides at all clusters
for (Entry<StopCluster, Ride> entry : retainedRides.entries()) {
StopCluster cluster = entry.getKey();
Ride ride = entry.getValue();
for (Stop stop : cluster.children) {
TransitStop tstop = graph.index.stopVertexForStop.get(stop);
// Iterate over street intersections in the vicinity of this particular transit stop.
// Shift the time range at this transit stop, merging it into that for all reachable street intersections.
// FIXME stopTreeCache.getDistancesForStop(tstop);
TObjectIntMap<Vertex> distanceToVertex = null;
for (TObjectIntIterator<Vertex> iter = distanceToVertex.iterator(); iter.hasNext(); ) {
iter.advance();
Vertex vertex = iter.key();
// distance in meters over walkspeed in meters per second --> seconds
int egressWalkTimeSeconds = (int) (iter.value() / request.walkSpeed);
if (egressWalkTimeSeconds > request.maxWalkTime * 60) {
continue;
}
int propagated_min = ride.dlb + egressWalkTimeSeconds;
int propagated_max = ride.dub + egressWalkTimeSeconds;
// FIXME HACK
int propagated_avg = (int) (((long) propagated_min + propagated_max) / 2);
int existing_min = minSurface.times.get(vertex);
int existing_max = maxSurface.times.get(vertex);
int existing_avg = avgSurface.times.get(vertex);
// which is not necessarily wrong but it's a crude way to perform the combination
if (existing_min == TimeSurface.UNREACHABLE || existing_min > propagated_min) {
minSurface.times.put(vertex, propagated_min);
}
if (existing_max == TimeSurface.UNREACHABLE || existing_max > propagated_max) {
maxSurface.times.put(vertex, propagated_max);
}
if (existing_avg == TimeSurface.UNREACHABLE || existing_avg > propagated_avg) {
avgSurface.times.put(vertex, propagated_avg);
}
}
}
}
LOG.info("Done with propagation.");
/* Store the results in a field in the router object. */
timeSurfaceRangeSet = new TimeSurface.RangeSet();
timeSurfaceRangeSet.min = minSurface;
timeSurfaceRangeSet.max = maxSurface;
timeSurfaceRangeSet.avg = avgSurface;
}
Aggregations