Search in sources :

Example 6 with Router

use of org.opentripplanner.standalone.Router 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;
}
Also used : StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Router(org.opentripplanner.standalone.Router) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Point(com.vividsolutions.jts.geom.Point) Date(java.util.Date) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 7 with Router

use of org.opentripplanner.standalone.Router in project OpenTripPlanner by opentripplanner.

the class TileService method tileGet.

@GET
@Produces("image/*")
public Response tileGet() throws Exception {
    Envelope2D env = SlippyTile.tile2Envelope(x, y, z);
    TileRequest tileRequest = new TileRequest(env, 256, 256);
    RoutingRequest sptRequestA = buildRequest();
    Layer layer = layers.get(0);
    Style style = styles.get(0);
    RenderRequest renderRequest = new RenderRequest(format, layer, style, true, false);
    Router router = otpServer.getRouter(routerId);
    // router.renderer.getResponse(tileRequest, sptRequestA, sptRequestB, renderRequest);
    return null;
}
Also used : TileRequest(org.opentripplanner.analyst.request.TileRequest) Style(org.opentripplanner.api.parameter.Style) RenderRequest(org.opentripplanner.analyst.request.RenderRequest) Router(org.opentripplanner.standalone.Router) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Envelope2D(org.geotools.geometry.Envelope2D) Layer(org.opentripplanner.api.parameter.Layer) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with Router

use of org.opentripplanner.standalone.Router in project OpenTripPlanner by opentripplanner.

the class ClusterGraphService method getRouter.

@Override
public synchronized Router getRouter(String graphId) {
    GRAPH_DIR.mkdirs();
    if (!graphMap.containsKey(graphId)) {
        try {
            if (!bucketCached(graphId)) {
                if (!workOffline) {
                    downloadGraphSourceFiles(graphId, GRAPH_DIR);
                }
            }
        } catch (IOException e) {
            LOG.error("exception finding graph {}", graphId, e);
        }
        CommandLineParameters params = new CommandLineParameters();
        params.build = new File(GRAPH_DIR, graphId);
        params.inMemory = true;
        GraphBuilder gbt = GraphBuilder.forDirectory(params, params.build);
        gbt.run();
        Graph g = gbt.getGraph();
        g.routerId = graphId;
        g.index(new DefaultStreetVertexIndexFactory());
        g.index.clusterStopsAsNeeded();
        Router r = new Router(graphId, g);
        return r;
    } else {
        return graphMap.get(graphId);
    }
}
Also used : CommandLineParameters(org.opentripplanner.standalone.CommandLineParameters) Graph(org.opentripplanner.routing.graph.Graph) Router(org.opentripplanner.standalone.Router) GraphBuilder(org.opentripplanner.graph_builder.GraphBuilder) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) ZipFile(java.util.zip.ZipFile)

Example 9 with Router

use of org.opentripplanner.standalone.Router in project OpenTripPlanner by opentripplanner.

the class SurfaceResource method differenceTileGet.

/**
 * Renders a raster tile for showing the difference between two TimeSurfaces.
 * This service is included as a way to provide difference tiles using existing mechanisms in OTP.
 * TODO However, there is some room for debate around how differences are expressed in URLs.
 * We may want a more general purpose mechanism for combining time surfaces.
 * For example you could make a web service request to create a time surface A-B or A+B, and the server would give
 * you an ID for that surface, and then you could use that ID anywhere a surface ID is required. Perhaps internally
 * there would be some sort of DifferenceTimeSurface subclass that could just drop in anywhere TimeSurface is used.
 * This approach would be more stateful but more flexible.
 *
 * @author hannesj
 *
 * @param surfaceId The id of the first surface
 * @param compareToSurfaceId The id of of the surface, which is compared to the first surface
 */
@Path("/{surfaceId}/differencetiles/{compareToSurfaceId}/{z}/{x}/{y}.png")
@GET
@Produces("image/png")
public Response differenceTileGet(@PathParam("surfaceId") Integer surfaceId, @PathParam("compareToSurfaceId") Integer compareToSurfaceId, @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.");
    TimeSurface surfB = otpServer.surfaceCache.get(compareToSurfaceId);
    if (surfB == null)
        return badRequest("Unrecognized surface ID.");
    if (!surfA.routerId.equals(surfB.routerId)) {
        return badRequest("Both surfaces must be from the same router to perform subtraction.");
    }
    TileRequest tileRequest = new TileRequest(env, 256, 256);
    MIMEImageFormat imageFormat = new MIMEImageFormat("image/png");
    RenderRequest renderRequest = new RenderRequest(imageFormat, Layer.DIFFERENCE, Style.DIFFERENCE, true, false);
    // TODO why can't the renderer be static?
    Router router = otpServer.getRouter(surfA.routerId);
    return router.renderer.getResponse(tileRequest, surfA, surfB, 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 10 with Router

use of org.opentripplanner.standalone.Router in project OpenTripPlanner by opentripplanner.

the class SurfaceResource method getRaster.

/**
 * Produce a single grayscale raster of travel time, like travel time tiles but not broken into tiles.
 */
@Path("/{surfaceId}/raster")
@GET
@Produces("image/*")
public Response getRaster(@PathParam("surfaceId") Integer surfaceId, @QueryParam("width") @DefaultValue("1024") Integer width, @QueryParam("height") @DefaultValue("768") Integer height, @QueryParam("resolution") Double resolution, @QueryParam("time") IsoTimeParameter time, @QueryParam("format") @DefaultValue("image/geotiff") MIMEImageFormat format, @QueryParam("crs") @DefaultValue("EPSG:4326") CRSParameter crs) throws Exception {
    TimeSurface surface = otpServer.surfaceCache.get(surfaceId);
    Router router = otpServer.getRouter(surface.routerId);
    // BoundingBox is a subclass of Envelope, an Envelope2D constructor parameter
    Envelope2D bbox = new Envelope2D(router.graph.getGeomIndex().getBoundingBox(crs.crs));
    if (resolution != null) {
        width = (int) Math.ceil(bbox.width / resolution);
        height = (int) Math.ceil(bbox.height / resolution);
    }
    TileRequest tileRequest = new TileRequest(bbox, width, height);
    RenderRequest renderRequest = new RenderRequest(format, Layer.TRAVELTIME, Style.GRAY, false, false);
    return router.renderer.getResponse(tileRequest, surface, null, renderRequest);
}
Also used : TimeSurface(org.opentripplanner.analyst.TimeSurface) TileRequest(org.opentripplanner.analyst.request.TileRequest) Router(org.opentripplanner.standalone.Router) RenderRequest(org.opentripplanner.analyst.request.RenderRequest) Envelope2D(org.geotools.geometry.Envelope2D) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Router (org.opentripplanner.standalone.Router)22 GET (javax.ws.rs.GET)9 Produces (javax.ws.rs.Produces)8 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)8 Path (javax.ws.rs.Path)6 Graph (org.opentripplanner.routing.graph.Graph)6 Envelope2D (org.geotools.geometry.Envelope2D)5 TimeSurface (org.opentripplanner.analyst.TimeSurface)5 TileRequest (org.opentripplanner.analyst.request.TileRequest)5 RenderRequest (org.opentripplanner.analyst.request.RenderRequest)4 ArrayList (java.util.ArrayList)3 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)3 GraphPathFinder (org.opentripplanner.routing.impl.GraphPathFinder)3 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)3 CommandLineParameters (org.opentripplanner.standalone.CommandLineParameters)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 Date (java.util.Date)2 MIMEImageFormat (org.opentripplanner.api.parameter.MIMEImageFormat)2 GenericLocation (org.opentripplanner.common.model.GenericLocation)2