Search in sources :

Example 6 with TimeSurface

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();
}
Also used : PointSet(org.opentripplanner.analyst.PointSet) SampleSet(org.opentripplanner.analyst.SampleSet) TimeSurface(org.opentripplanner.analyst.TimeSurface) OutputStream(java.io.OutputStream) ResultSet(org.opentripplanner.analyst.ResultSet) Router(org.opentripplanner.standalone.Router) StreamingOutput(javax.ws.rs.core.StreamingOutput) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 7 with TimeSurface

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);
}
Also used : TimeSurface(org.opentripplanner.analyst.TimeSurface) TileRequest(org.opentripplanner.analyst.request.TileRequest) RenderRequest(org.opentripplanner.analyst.request.RenderRequest) Router(org.opentripplanner.standalone.Router) MIMEImageFormat(org.opentripplanner.api.parameter.MIMEImageFormat) Envelope2D(org.geotools.geometry.Envelope2D) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with TimeSurface

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();
}
Also used : FeatureJSON(org.geotools.geojson.feature.FeatureJSON) FeatureCollection(org.geotools.feature.FeatureCollection) TimeSurface(org.opentripplanner.analyst.TimeSurface) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) IsochroneData(org.opentripplanner.analyst.core.IsochroneData) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 9 with TimeSurface

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;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TimeSurface(org.opentripplanner.analyst.TimeSurface)

Aggregations

TimeSurface (org.opentripplanner.analyst.TimeSurface)9 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Router (org.opentripplanner.standalone.Router)5 Produces (javax.ws.rs.Produces)3 Envelope2D (org.geotools.geometry.Envelope2D)3 RenderRequest (org.opentripplanner.analyst.request.RenderRequest)3 TileRequest (org.opentripplanner.analyst.request.TileRequest)3 OutputStream (java.io.OutputStream)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 MIMEImageFormat (org.opentripplanner.api.parameter.MIMEImageFormat)2 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)2 Vertex (org.opentripplanner.routing.graph.Vertex)2 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 POST (javax.ws.rs.POST)1 FeatureCollection (org.geotools.feature.FeatureCollection)1 FeatureJSON (org.geotools.geojson.feature.FeatureJSON)1