use of com.vividsolutions.jts.geom.Coordinate in project OpenTripPlanner by opentripplanner.
the class IsoChroneSPTRendererRecursiveGrid method computeInitialPoints.
/**
* Compute a set of initial coordinates for the given SPT
*
* @param spt
* @return
*/
private List<Coordinate> computeInitialPoints(ShortestPathTree spt) {
List<Coordinate> retval = new ArrayList<Coordinate>(spt.getVertexCount());
for (State s : spt.getAllStates()) {
Vertex v = s.getVertex();
// Take only street
if (v instanceof StreetVertex) {
retval.add(v.getCoordinate());
}
}
LOG.debug("Created {} initial points from {} vertexes.", retval.size(), spt.getVertexCount());
return retval;
}
use of com.vividsolutions.jts.geom.Coordinate 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 com.vividsolutions.jts.geom.Coordinate in project OpenTripPlanner by opentripplanner.
the class SampleGridRenderer method sampleSPT.
/**
* Sample a SPT using a SPTWalker and an AccumulativeGridSampler.
*/
public static void sampleSPT(final ShortestPathTree spt, ZSampleGrid<WTWD> sampleGrid, final double gridSizeMeters, final double offRoadDistanceMeters, final double offRoadWalkSpeedMps, final double maxWalkDistance, final int maxTimeSec, final double cosLat) {
AccumulativeMetric<WTWD> accMetric = new WTWDAccumulativeMetric(cosLat, offRoadDistanceMeters, offRoadWalkSpeedMps, gridSizeMeters);
final AccumulativeGridSampler<WTWD> gridSampler = new AccumulativeGridSampler<WTWD>(sampleGrid, accMetric);
// At which distance we split edges along the geometry during sampling.
// For best results, this should be slighly lower than the grid size.
double walkerSplitDistanceMeters = gridSizeMeters * 0.5;
SPTWalker johnny = new SPTWalker(spt);
johnny.walk(new SPTVisitor() {
@Override
public final boolean accept(Edge e) {
return e instanceof StreetEdge;
}
@Override
public final void visit(Edge e, Coordinate c, State s0, State s1, double d0, double d1, double speedAlongEdge) {
double wd0 = s0.getWalkDistance() + d0;
double wd1 = s0.getWalkDistance() + d1;
double t0 = wd0 > maxWalkDistance ? Double.POSITIVE_INFINITY : s0.getActiveTime() + d0 / speedAlongEdge;
double t1 = wd1 > maxWalkDistance ? Double.POSITIVE_INFINITY : s1.getActiveTime() + d1 / speedAlongEdge;
if (t0 < maxTimeSec || t1 < maxTimeSec) {
if (!Double.isInfinite(t0) || !Double.isInfinite(t1)) {
WTWD z = new WTWD();
z.w = 1.0;
z.d = 0.0;
if (t0 < t1) {
z.wTime = t0;
z.wBoardings = s0.getNumBoardings();
z.wWalkDist = s0.getWalkDistance() + d0;
} else {
z.wTime = t1;
z.wBoardings = s1.getNumBoardings();
z.wWalkDist = s1.getWalkDistance() + d1;
}
gridSampler.addSamplingPoint(c, z, offRoadWalkSpeedMps);
}
}
}
}, walkerSplitDistanceMeters);
gridSampler.close();
}
use of com.vividsolutions.jts.geom.Coordinate in project OpenTripPlanner by opentripplanner.
the class Graph method calculateTransitCenter.
/**
* Calculates Transit center from median of coordinates of all transitStops if graph
* has transit. If it doesn't it isn't calculated. (mean walue of min, max latitude and longitudes are used)
*
* Transit center is saved in center variable
*
* This speeds up calculation, but problem is that median needs to have all of latitudes/longitudes
* in memory, this can become problematic in large installations. It works without a problem on New York State.
* @see GraphEnvelope
*/
public void calculateTransitCenter() {
if (hasTransit) {
TDoubleList latitudes = new TDoubleLinkedList();
TDoubleList longitudes = new TDoubleLinkedList();
Median median = new Median();
getVertices().stream().filter(v -> v instanceof TransitStop).forEach(v -> {
latitudes.add(v.getLat());
longitudes.add(v.getLon());
});
median.setData(latitudes.toArray());
double medianLatitude = median.evaluate();
median = new Median();
median.setData(longitudes.toArray());
double medianLongitude = median.evaluate();
this.center = new Coordinate(medianLongitude, medianLatitude);
}
}
use of com.vividsolutions.jts.geom.Coordinate in project OpenTripPlanner by opentripplanner.
the class Graph method calculateEnvelope.
/**
* Calculates envelope out of all OSM coordinates
*
* Transit stops are added to the envelope as they are added to the graph
*/
public void calculateEnvelope() {
this.envelope = new WorldEnvelope();
for (Vertex v : this.getVertices()) {
Coordinate c = v.getCoordinate();
this.envelope.expandToInclude(c);
}
}
Aggregations