use of org.opentripplanner.common.geometry.SparseMatrixZSampleGrid in project OpenTripPlanner by opentripplanner.
the class SampleGridRenderer method getSampleGrid.
/**
* @param spgRequest
* @param sptRequest
* @return
*/
public ZSampleGrid<WTWD> getSampleGrid(SampleGridRequest spgRequest, RoutingRequest sptRequest) {
final double offRoadDistanceMeters = spgRequest.offRoadDistanceMeters;
// m/s, off-road walk speed
final double offRoadWalkSpeedMps = 1.00;
// 1. Compute the Shortest Path Tree.
long t0 = System.currentTimeMillis();
long tOvershot = (long) (2 * offRoadDistanceMeters / offRoadWalkSpeedMps);
sptRequest.worstTime = (sptRequest.dateTime + (sptRequest.arriveBy ? -spgRequest.maxTimeSec - tOvershot : spgRequest.maxTimeSec + tOvershot));
sptRequest.batch = (true);
sptRequest.setRoutingContext(graph);
// TODO swap in different state dominance logic (earliest arrival, pareto, etc.)
final ShortestPathTree spt = new AStar().getShortestPathTree(sptRequest);
// 3. Create a sample grid based on the SPT.
long t1 = System.currentTimeMillis();
Coordinate coordinateOrigin = spgRequest.coordinateOrigin;
if (coordinateOrigin == null)
coordinateOrigin = sptRequest.from.getCoordinate();
final double gridSizeMeters = spgRequest.precisionMeters;
final double cosLat = FastMath.cos(toRadians(coordinateOrigin.y));
double dY = Math.toDegrees(gridSizeMeters / SphericalDistanceLibrary.RADIUS_OF_EARTH_IN_M);
double dX = dY / cosLat;
SparseMatrixZSampleGrid<WTWD> sampleGrid = new SparseMatrixZSampleGrid<WTWD>(16, spt.getVertexCount(), dX, dY, coordinateOrigin);
sampleSPT(spt, sampleGrid, gridSizeMeters, offRoadDistanceMeters, offRoadWalkSpeedMps, sptRequest.getMaxWalkDistance(), spgRequest.maxTimeSec, cosLat);
sptRequest.cleanup();
long t2 = System.currentTimeMillis();
LOG.info("Computed SPT in {}msec, {}msec for sampling ({} msec total)", (int) (t1 - t0), (int) (t2 - t1), (int) (t2 - t0));
return sampleGrid;
}
use of org.opentripplanner.common.geometry.SparseMatrixZSampleGrid 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;
}
Aggregations