Search in sources :

Example 16 with Router

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

the class GraphInspectorTileResource method getLayers.

/**
 * Gets all layer names
 *
 * Used in fronted to create layer chooser
 * @return
 */
@GET
@Path("layers")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML + Q, MediaType.TEXT_XML + Q })
public InspectorLayersList getLayers() {
    Router router = otpServer.getRouter(routerId);
    InspectorLayersList layersList = new InspectorLayersList(router.tileRendererManager.getRenderers());
    return layersList;
}
Also used : Router(org.opentripplanner.standalone.Router) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 17 with Router

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

the class SurfaceResource method createSurface.

@POST
public Response createSurface(@QueryParam("cutoffMinutes") @DefaultValue("90") int cutoffMinutes, @QueryParam("routerId") String routerId) {
    // Build the request
    try {
        // batch must be true
        RoutingRequest req = buildRequest();
        // routerId is optional -- select default graph if not set
        Router router = otpServer.getRouter(routerId);
        req.setRoutingContext(router.graph);
        EarliestArrivalSearch sptService = new EarliestArrivalSearch();
        sptService.maxDuration = (60 * cutoffMinutes);
        ShortestPathTree spt = sptService.getShortestPathTree(req);
        req.cleanup();
        if (spt != null) {
            TimeSurface surface = new TimeSurface(spt);
            surface.params = Maps.newHashMap();
            for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
                // include only the first instance of each query parameter
                surface.params.put(e.getKey(), e.getValue().get(0));
            }
            surface.cutoffMinutes = cutoffMinutes;
            otpServer.surfaceCache.add(surface);
            // .created(URI)
            return Response.ok().entity(new TimeSurfaceShort(surface)).build();
        } else {
            return Response.noContent().entity("NO SPT").build();
        }
    } catch (ParameterException pex) {
        return Response.status(Response.Status.BAD_REQUEST).entity("BAD USER").build();
    }
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) TimeSurfaceShort(org.opentripplanner.api.model.TimeSurfaceShort) TimeSurface(org.opentripplanner.analyst.TimeSurface) Router(org.opentripplanner.standalone.Router) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) EarliestArrivalSearch(org.opentripplanner.routing.algorithm.EarliestArrivalSearch) ArrayList(java.util.ArrayList) List(java.util.List) ParameterException(org.opentripplanner.api.common.ParameterException) Map(java.util.Map) POST(javax.ws.rs.POST)

Example 18 with Router

use of org.opentripplanner.standalone.Router 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 19 with Router

use of org.opentripplanner.standalone.Router 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 20 with Router

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

the class RoutingResource method buildRequest.

/**
 * Range/sanity check the query parameter fields and build a Request object from them.
 *
 * @throws ParameterException when there is a problem interpreting a query parameter
 */
protected RoutingRequest buildRequest() throws ParameterException {
    Router router = otpServer.getRouter(routerId);
    RoutingRequest request = router.defaultRoutingRequest.clone();
    request.routerId = routerId;
    // router configuration and cloned. We check whether each parameter was supplied before overwriting the default.
    if (fromPlace != null)
        request.setFromString(fromPlace);
    if (toPlace != null)
        request.setToString(toPlace);
    {
        // FIXME: move into setter method on routing request
        TimeZone tz;
        tz = router.graph.getTimeZone();
        if (date == null && time != null) {
            // Time was provided but not date
            LOG.debug("parsing ISO datetime {}", time);
            try {
                // If the time query param doesn't specify a timezone, use the graph's default. See issue #1373.
                DatatypeFactory df = javax.xml.datatype.DatatypeFactory.newInstance();
                XMLGregorianCalendar xmlGregCal = df.newXMLGregorianCalendar(time);
                GregorianCalendar gregCal = xmlGregCal.toGregorianCalendar();
                if (xmlGregCal.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
                    gregCal.setTimeZone(tz);
                }
                Date d2 = gregCal.getTime();
                request.setDateTime(d2);
            } catch (DatatypeConfigurationException e) {
                request.setDateTime(date, time, tz);
            }
        } else {
            request.setDateTime(date, time, tz);
        }
    }
    if (wheelchair != null)
        request.setWheelchairAccessible(wheelchair);
    if (numItineraries != null)
        request.setNumItineraries(numItineraries);
    if (maxWalkDistance != null) {
        request.setMaxWalkDistance(maxWalkDistance);
        request.maxTransferWalkDistance = maxWalkDistance;
    }
    if (maxPreTransitTime != null)
        request.setMaxPreTransitTime(maxPreTransitTime);
    if (walkReluctance != null)
        request.setWalkReluctance(walkReluctance);
    if (waitReluctance != null)
        request.setWaitReluctance(waitReluctance);
    if (waitAtBeginningFactor != null)
        request.setWaitAtBeginningFactor(waitAtBeginningFactor);
    if (walkSpeed != null)
        request.walkSpeed = walkSpeed;
    if (bikeSpeed != null)
        request.bikeSpeed = bikeSpeed;
    if (bikeSwitchTime != null)
        request.bikeSwitchTime = bikeSwitchTime;
    if (bikeSwitchCost != null)
        request.bikeSwitchCost = bikeSwitchCost;
    if (optimize != null) {
        // Optimize types are basically combined presets of routing parameters, except for triangle
        request.setOptimize(optimize);
        if (optimize == OptimizeType.TRIANGLE) {
            if (triangleSafetyFactor == null || triangleSlopeFactor == null || triangleTimeFactor == null) {
                throw new ParameterException(Message.UNDERSPECIFIED_TRIANGLE);
            }
            if (triangleSafetyFactor == null && triangleSlopeFactor == null && triangleTimeFactor == null) {
                throw new ParameterException(Message.TRIANGLE_VALUES_NOT_SET);
            }
            // FIXME couldn't this be simplified by only specifying TWO of the values?
            if (Math.abs(triangleSafetyFactor + triangleSlopeFactor + triangleTimeFactor - 1) > Math.ulp(1) * 3) {
                throw new ParameterException(Message.TRIANGLE_NOT_AFFINE);
            }
            request.setTriangleSafetyFactor(triangleSafetyFactor);
            request.setTriangleSlopeFactor(triangleSlopeFactor);
            request.setTriangleTimeFactor(triangleTimeFactor);
        }
    }
    if (arriveBy != null)
        request.setArriveBy(arriveBy);
    if (showIntermediateStops != null)
        request.showIntermediateStops = showIntermediateStops;
    if (intermediatePlaces != null)
        request.setIntermediatePlacesFromStrings(intermediatePlaces);
    if (preferredRoutes != null)
        request.setPreferredRoutes(preferredRoutes);
    if (otherThanPreferredRoutesPenalty != null)
        request.setOtherThanPreferredRoutesPenalty(otherThanPreferredRoutesPenalty);
    if (preferredAgencies != null)
        request.setPreferredAgencies(preferredAgencies);
    if (unpreferredRoutes != null)
        request.setUnpreferredRoutes(unpreferredRoutes);
    if (unpreferredAgencies != null)
        request.setUnpreferredAgencies(unpreferredAgencies);
    if (walkBoardCost != null)
        request.setWalkBoardCost(walkBoardCost);
    if (bikeBoardCost != null)
        request.setBikeBoardCost(bikeBoardCost);
    if (bannedRoutes != null)
        request.setBannedRoutes(bannedRoutes);
    if (bannedAgencies != null)
        request.setBannedAgencies(bannedAgencies);
    HashMap<AgencyAndId, BannedStopSet> bannedTripMap = makeBannedTripMap(bannedTrips);
    if (bannedTripMap != null)
        request.bannedTrips = bannedTripMap;
    if (bannedStops != null)
        request.setBannedStops(bannedStops);
    if (bannedStopsHard != null)
        request.setBannedStopsHard(bannedStopsHard);
    // See comment on RoutingRequest.transferPentalty.
    if (transferPenalty != null)
        request.transferPenalty = transferPenalty;
    if (optimize == OptimizeType.TRANSFERS) {
        optimize = OptimizeType.QUICK;
        request.transferPenalty += 1800;
    }
    if (batch != null)
        request.batch = batch;
    if (optimize != null)
        request.setOptimize(optimize);
    /* Temporary code to get bike/car parking and renting working. */
    if (modes != null) {
        modes.applyToRoutingRequest(request);
        request.setModes(request.modes);
    }
    if (request.allowBikeRental && bikeSpeed == null) {
        // slower bike speed for bike sharing, based on empirical evidence from DC.
        request.bikeSpeed = 4.3;
    }
    if (boardSlack != null)
        request.boardSlack = boardSlack;
    if (alightSlack != null)
        request.alightSlack = alightSlack;
    if (minTransferTime != null)
        // TODO rename field in routingrequest
        request.transferSlack = minTransferTime;
    if (nonpreferredTransferPenalty != null)
        request.nonpreferredTransferPenalty = nonpreferredTransferPenalty;
    if (request.boardSlack + request.alightSlack > request.transferSlack) {
        throw new RuntimeException("Invalid parameters: " + "transfer slack must be greater than or equal to board slack plus alight slack");
    }
    if (maxTransfers != null)
        request.maxTransfers = maxTransfers;
    final long NOW_THRESHOLD_MILLIS = 15 * 60 * 60 * 1000;
    boolean tripPlannedForNow = Math.abs(request.getDateTime().getTime() - new Date().getTime()) < NOW_THRESHOLD_MILLIS;
    // TODO the same thing for GTFS-RT
    request.useBikeRentalAvailabilityInformation = (tripPlannedForNow);
    if (startTransitStopId != null && !startTransitStopId.isEmpty())
        request.startingTransitStopId = AgencyAndId.convertFromString(startTransitStopId);
    if (startTransitTripId != null && !startTransitTripId.isEmpty())
        request.startingTransitTripId = AgencyAndId.convertFromString(startTransitTripId);
    if (clampInitialWait != null)
        request.clampInitialWait = clampInitialWait;
    if (reverseOptimizeOnTheFly != null)
        request.reverseOptimizeOnTheFly = reverseOptimizeOnTheFly;
    if (ignoreRealtimeUpdates != null)
        request.ignoreRealtimeUpdates = ignoreRealtimeUpdates;
    if (disableRemainingWeightHeuristic != null)
        request.disableRemainingWeightHeuristic = disableRemainingWeightHeuristic;
    if (maxHours != null)
        request.maxHours = maxHours;
    if (useRequestedDateTimeInMaxHours != null)
        request.useRequestedDateTimeInMaxHours = useRequestedDateTimeInMaxHours;
    if (disableAlertFiltering != null)
        request.disableAlertFiltering = disableAlertFiltering;
    if (geoidElevation != null)
        request.geoidElevation = geoidElevation;
    // getLocale function returns defaultLocale if locale is null
    request.locale = ResourceBundleSingleton.INSTANCE.getLocale(locale);
    return request;
}
Also used : DatatypeFactory(javax.xml.datatype.DatatypeFactory) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BannedStopSet(org.opentripplanner.routing.request.BannedStopSet) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Router(org.opentripplanner.standalone.Router) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

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