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();
}
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);
}
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;
}
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;
}
Aggregations