Search in sources :

Example 6 with IsochroneData

use of org.opentripplanner.analyst.core.IsochroneData 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 7 with IsochroneData

use of org.opentripplanner.analyst.core.IsochroneData in project OpenTripPlanner by opentripplanner.

the class ResultSet method buildIsochrones.

private void buildIsochrones(int[] times, PointSet targets) {
    ZSampleGrid zs = IsochroneGenerator.makeGrid(targets, times, 1.3);
    List<IsochroneData> id = IsochroneGenerator.getIsochronesAccumulative(zs, 5, 120, 24);
    this.isochrones = new IsochroneData[id.size()];
    id.toArray(this.isochrones);
}
Also used : ZSampleGrid(org.opentripplanner.common.geometry.ZSampleGrid) IsochroneData(org.opentripplanner.analyst.core.IsochroneData)

Example 8 with IsochroneData

use of org.opentripplanner.analyst.core.IsochroneData in project OpenTripPlanner by opentripplanner.

the class PropagatedTimesStore method makeIsochroneForVertices.

/**
 * This bypasses a bunch of TimeSurface conversion/copy steps we were going though and makes the isochrones directly.
 * This assumes that the target indexes in this router/propagatedTimesStore are vertex indexes, not pointset indexes.
 * Called three times on min/avg/max to create the three elements of a ResultEnvelope.
 */
private ResultSet makeIsochroneForVertices(int[] times) {
    final int spacing = 5;
    final int nMax = 24;
    final int cutoffMinutes = 120;
    final double gridSize = IsochroneGenerator.GRID_SIZE_METERS;
    final double offroadDistanceMeters = gridSize * IsochroneGenerator.WALK_DISTANCE_GRID_SIZE_RATIO;
    SparseMatrixZSampleGrid<WTWD> grid = makeSampleGridForVertices(times, gridSize);
    long t0 = System.currentTimeMillis();
    DelaunayIsolineBuilder<WTWD> isolineBuilder = new DelaunayIsolineBuilder<>(grid.delaunayTriangulate(), new WTWD.IsolineMetric());
    List<IsochroneData> isoData = new ArrayList<IsochroneData>();
    for (int minutes = spacing, n = 0; minutes <= cutoffMinutes && n < nMax; minutes += spacing, n++) {
        int seconds = minutes * 60;
        WTWD z0 = new WTWD();
        z0.w = 1.0;
        z0.wTime = seconds;
        z0.d = offroadDistanceMeters;
        IsochroneData isochrone = new IsochroneData(seconds, isolineBuilder.computeIsoline(z0));
        isoData.add(isochrone);
    }
    long t1 = System.currentTimeMillis();
    ResultSet resultSet = new ResultSet();
    resultSet.isochrones = new IsochroneData[isoData.size()];
    isoData.toArray(resultSet.isochrones);
    LOG.debug("Computed {} isochrones in {} msec", isoData.size(), (int) (t1 - t0));
    return resultSet;
}
Also used : WTWD(org.opentripplanner.analyst.request.SampleGridRenderer.WTWD) DelaunayIsolineBuilder(org.opentripplanner.common.geometry.DelaunayIsolineBuilder) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) ResultSet(org.opentripplanner.analyst.ResultSet) IsochroneData(org.opentripplanner.analyst.core.IsochroneData)

Example 9 with IsochroneData

use of org.opentripplanner.analyst.core.IsochroneData in project OpenTripPlanner by opentripplanner.

the class IsoChroneSPTRendererRecursiveGrid method getIsochrones.

/**
 * @param isoChroneRequest
 * @param sptRequest
 * @return
 */
@Override
public List<IsochroneData> getIsochrones(IsoChroneRequest isoChroneRequest, RoutingRequest sptRequest) {
    if (sptRequest.routerId != null && !sptRequest.routerId.isEmpty())
        throw new IllegalArgumentException("TODO: SampleSource is not multi-router compatible (yet).");
    // 1. Compute the Shortest Path Tree.
    long t0 = System.currentTimeMillis();
    sptRequest.worstTime = (sptRequest.dateTime + (sptRequest.arriveBy ? -isoChroneRequest.maxCutoffSec : isoChroneRequest.maxCutoffSec));
    sptRequest.batch = true;
    sptRequest.setRoutingContext(graph);
    // TODO handle different path dominance conditions
    final ShortestPathTree spt = new AStar().getShortestPathTree(sptRequest);
    sptRequest.cleanup();
    // 2. Compute the set of initial points
    long t1 = System.currentTimeMillis();
    List<Coordinate> initialPoints = computeInitialPoints(spt);
    // 3. Compute the isochrone based on the SPT.
    ZFunc timeFunc = new ZFunc() {

        @Override
        public long z(Coordinate c) {
            Sample sample = sampleSource.getSample(c.x, c.y);
            if (sample == null) {
                return Long.MAX_VALUE;
            }
            Long z = sample.eval(spt);
            return z;
        }
    };
    // TODO Snap the center as XYZ tile grid for better sample-reuse (if using sample cache).
    Coordinate center = sptRequest.from.getCoordinate();
    double gridSizeMeters = isoChroneRequest.precisionMeters;
    double dY = Math.toDegrees(gridSizeMeters / SphericalDistanceLibrary.RADIUS_OF_EARTH_IN_M);
    double dX = dY / Math.cos(Math.toRadians(center.x));
    LOG.info("dX={}, dY={}", dX, dY);
    RecursiveGridIsolineBuilder isolineBuilder = new RecursiveGridIsolineBuilder(dX, dY, center, timeFunc, initialPoints);
    isolineBuilder.setDebugCrossingEdges(isoChroneRequest.includeDebugGeometry);
    isolineBuilder.setDebugSeedGrid(isoChroneRequest.includeDebugGeometry);
    List<IsochroneData> isochrones = new ArrayList<IsochroneData>();
    for (Integer cutoffSec : isoChroneRequest.cutoffSecList) {
        IsochroneData isochrone = new IsochroneData(cutoffSec, isolineBuilder.computeIsoline(cutoffSec));
        if (isoChroneRequest.includeDebugGeometry)
            isochrone.debugGeometry = isolineBuilder.getDebugGeometry();
        isochrones.add(isochrone);
    }
    long t2 = System.currentTimeMillis();
    LOG.info("Computed SPT in {}msec, {} isochrones in {}msec", (int) (t1 - t0), isochrones.size(), (int) (t2 - t1));
    return isochrones;
}
Also used : Sample(org.opentripplanner.analyst.core.Sample) AStar(org.opentripplanner.routing.algorithm.AStar) ArrayList(java.util.ArrayList) ZFunc(org.opentripplanner.common.geometry.RecursiveGridIsolineBuilder.ZFunc) IsochroneData(org.opentripplanner.analyst.core.IsochroneData) RecursiveGridIsolineBuilder(org.opentripplanner.common.geometry.RecursiveGridIsolineBuilder) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Aggregations

IsochroneData (org.opentripplanner.analyst.core.IsochroneData)9 ArrayList (java.util.ArrayList)6 WTWD (org.opentripplanner.analyst.request.SampleGridRenderer.WTWD)5 DelaunayIsolineBuilder (org.opentripplanner.common.geometry.DelaunayIsolineBuilder)5 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 ResultSet (org.opentripplanner.analyst.ResultSet)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 OutputStream (java.io.OutputStream)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 DefaultFeatureCollection (org.geotools.feature.DefaultFeatureCollection)1 FeatureCollection (org.geotools.feature.FeatureCollection)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 FeatureJSON (org.geotools.geojson.feature.FeatureJSON)1 TimeSurface (org.opentripplanner.analyst.TimeSurface)1 Sample (org.opentripplanner.analyst.core.Sample)1 SampleGridRenderer (org.opentripplanner.analyst.request.SampleGridRenderer)1 ZMetric (org.opentripplanner.common.geometry.IsolineBuilder.ZMetric)1 RecursiveGridIsolineBuilder (org.opentripplanner.common.geometry.RecursiveGridIsolineBuilder)1