Search in sources :

Example 1 with RecursiveGridIsolineBuilder

use of org.opentripplanner.common.geometry.RecursiveGridIsolineBuilder 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

Coordinate (com.vividsolutions.jts.geom.Coordinate)1 ArrayList (java.util.ArrayList)1 IsochroneData (org.opentripplanner.analyst.core.IsochroneData)1 Sample (org.opentripplanner.analyst.core.Sample)1 RecursiveGridIsolineBuilder (org.opentripplanner.common.geometry.RecursiveGridIsolineBuilder)1 ZFunc (org.opentripplanner.common.geometry.RecursiveGridIsolineBuilder.ZFunc)1 AStar (org.opentripplanner.routing.algorithm.AStar)1 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)1