Search in sources :

Example 1 with Envelope2D

use of org.geotools.geometry.Envelope2D 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 2 with Envelope2D

use of org.geotools.geometry.Envelope2D 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 3 with Envelope2D

use of org.geotools.geometry.Envelope2D 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)

Example 4 with Envelope2D

use of org.geotools.geometry.Envelope2D in project OpenTripPlanner by opentripplanner.

the class GraphInspectorTileResource method tileGet.

@GET
@Path("/tile/{layer}/{z}/{x}/{y}.{ext}")
@Produces("image/*")
public Response tileGet() throws Exception {
    // Re-use analyst
    Envelope2D env = SlippyTile.tile2Envelope(x, y, z);
    TileRequest tileRequest = new TileRequest(env, 256, 256);
    Router router = otpServer.getRouter(routerId);
    BufferedImage image = router.tileRendererManager.renderTile(tileRequest, layer);
    MIMEImageFormat format = new MIMEImageFormat("image/" + ext);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(image.getWidth() * image.getHeight() / 4);
    ImageIO.write(image, format.type, baos);
    CacheControl cc = new CacheControl();
    cc.setMaxAge(3600);
    cc.setNoCache(false);
    return Response.ok(baos.toByteArray()).type(format.toString()).cacheControl(cc).build();
}
Also used : TileRequest(org.opentripplanner.analyst.request.TileRequest) Router(org.opentripplanner.standalone.Router) MIMEImageFormat(org.opentripplanner.api.parameter.MIMEImageFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheControl(javax.ws.rs.core.CacheControl) Envelope2D(org.geotools.geometry.Envelope2D) BufferedImage(java.awt.image.BufferedImage) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with Envelope2D

use of org.geotools.geometry.Envelope2D 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)

Aggregations

Envelope2D (org.geotools.geometry.Envelope2D)6 GET (javax.ws.rs.GET)5 Produces (javax.ws.rs.Produces)5 TileRequest (org.opentripplanner.analyst.request.TileRequest)5 Router (org.opentripplanner.standalone.Router)5 Path (javax.ws.rs.Path)4 RenderRequest (org.opentripplanner.analyst.request.RenderRequest)4 TimeSurface (org.opentripplanner.analyst.TimeSurface)3 MIMEImageFormat (org.opentripplanner.api.parameter.MIMEImageFormat)3 BufferedImage (java.awt.image.BufferedImage)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 AffineTransformation (com.vividsolutions.jts.geom.util.AffineTransformation)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CacheControl (javax.ws.rs.core.CacheControl)1 Layer (org.opentripplanner.api.parameter.Layer)1 Style (org.opentripplanner.api.parameter.Style)1 TileRenderContext (org.opentripplanner.inspector.TileRenderer.TileRenderContext)1 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)1