Search in sources :

Example 1 with ZSampleGrid

use of org.opentripplanner.common.geometry.ZSampleGrid in project OpenTripPlanner by opentripplanner.

the class IsochroneGenerator method makeGrid.

/**
 * Make a ZSampleGrid from a PointSet and a parallel array of travel times for that PointSet.
 * Those times could come from a ResultSetWithTimes or directly from a PropagatedTimesStore, which has one
 * such array for each of min, avg, and max travel time over the departure time window it represents.
 * If your PointSet is dense enough (e.g. every block in a city) then this should yield a decent surface and
 * isochrones.
 * FIXME code duplication, this is ripped off from TimeSurface and should probably replace the version there as it is more generic.
 * @param walkSpeed the walk speed in meters per second
 * @return a grid suitable for making isochrones, based on an arbitrary PointSet and times to reach all those points.
 */
public static ZSampleGrid makeGrid(PointSet pointSet, int[] times, double walkSpeed) {
    // offroad walk distance roughly grid size
    final double D0 = WALK_DISTANCE_GRID_SIZE_RATIO * GRID_SIZE_METERS;
    // off-road walk speed in m/sec
    final double V0 = walkSpeed;
    // Use the first feature as the center of the projection
    Coordinate coordinateOrigin = pointSet.getCoordinate(0);
    final double cosLat = FastMath.cos(toRadians(coordinateOrigin.y));
    double dY = Math.toDegrees(GRID_SIZE_METERS / SphericalDistanceLibrary.RADIUS_OF_EARTH_IN_M);
    double dX = dY / cosLat;
    ZSampleGrid grid = new SparseMatrixZSampleGrid<WTWD>(16, times.length, dX, dY, coordinateOrigin);
    AccumulativeGridSampler.AccumulativeMetric<WTWD> metric = new SampleGridRenderer.WTWDAccumulativeMetric(cosLat, D0, V0, GRID_SIZE_METERS);
    AccumulativeGridSampler<WTWD> sampler = new AccumulativeGridSampler<>(grid, metric);
    // Iterate over every point in this PointSet, adding it to the ZSampleGrid
    for (int p = 0; p < times.length; p++) {
        int time = times[p];
        WTWD z = new WTWD();
        z.w = 1.0;
        z.d = 0.0;
        z.wTime = time;
        // unused
        z.wBoardings = 0;
        // unused
        z.wWalkDist = 0;
        sampler.addSamplingPoint(pointSet.getCoordinate(p), z, V0);
    }
    sampler.close();
    return grid;
}
Also used : SparseMatrixZSampleGrid(org.opentripplanner.common.geometry.SparseMatrixZSampleGrid) ZSampleGrid(org.opentripplanner.common.geometry.ZSampleGrid) WTWD(org.opentripplanner.analyst.request.SampleGridRenderer.WTWD) Coordinate(com.vividsolutions.jts.geom.Coordinate) AccumulativeGridSampler(org.opentripplanner.common.geometry.AccumulativeGridSampler) SparseMatrixZSampleGrid(org.opentripplanner.common.geometry.SparseMatrixZSampleGrid)

Example 2 with ZSampleGrid

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

Aggregations

ZSampleGrid (org.opentripplanner.common.geometry.ZSampleGrid)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 IsochroneData (org.opentripplanner.analyst.core.IsochroneData)1 WTWD (org.opentripplanner.analyst.request.SampleGridRenderer.WTWD)1 AccumulativeGridSampler (org.opentripplanner.common.geometry.AccumulativeGridSampler)1 SparseMatrixZSampleGrid (org.opentripplanner.common.geometry.SparseMatrixZSampleGrid)1