use of org.opengis.coverage.Coverage in project OpenTripPlanner by opentripplanner.
the class ElevationModule method buildGraph.
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
gridCoverageFactory.setGraph(graph);
Coverage gridCov = gridCoverageFactory.getGridCoverage();
// If gridCov is a GridCoverage2D, apply a bilinear interpolator. Otherwise, just use the
// coverage as is (note: UnifiedGridCoverages created by NEDGridCoverageFactoryImpl handle
// interpolation internally)
coverage = (gridCov instanceof GridCoverage2D) ? Interpolator2D.create((GridCoverage2D) gridCov, new InterpolationBilinear()) : gridCov;
log.info("Setting street elevation profiles from digital elevation model...");
List<StreetEdge> edgesWithElevation = new ArrayList<StreetEdge>();
int nProcessed = 0;
int nTotal = graph.countEdges();
for (Vertex gv : graph.getVertices()) {
for (Edge ee : gv.getOutgoing()) {
if (ee instanceof StreetWithElevationEdge) {
StreetWithElevationEdge edgeWithElevation = (StreetWithElevationEdge) ee;
processEdge(graph, edgeWithElevation);
if (edgeWithElevation.getElevationProfile() != null && !edgeWithElevation.isElevationFlattened()) {
edgesWithElevation.add(edgeWithElevation);
}
nProcessed += 1;
if (nProcessed % 50000 == 0) {
log.info("set elevation on {}/{} edges", nProcessed, nTotal);
double failurePercentage = nPointsOutsideDEM / nPointsEvaluated * 100;
if (failurePercentage > 50) {
log.warn("Fetching elevation failed at {}/{} points ({}%)", nPointsOutsideDEM, nPointsEvaluated, failurePercentage);
log.warn("Elevation is missing at a large number of points. DEM may be for the wrong region. " + "If it is unprojected, perhaps the axes are not in (longitude, latitude) order.");
}
}
}
}
}
@SuppressWarnings("unchecked") HashMap<Vertex, Double> extraElevation = (HashMap<Vertex, Double>) extra.get(ElevationPoint.class);
assignMissingElevations(graph, edgesWithElevation, extraElevation);
}
use of org.opengis.coverage.Coverage in project OpenTripPlanner by opentripplanner.
the class UnifiedGridCoverage method evaluate.
public double[] evaluate(DirectPosition point, double[] values) throws PointOutsideCoverageException, CannotEvaluateException {
for (Coverage region : regions) {
// GeneralEnvelope has a contains method, OpenGIS Envelope does not
GeneralEnvelope env = ((GeneralEnvelope) region.getEnvelope());
// especially important when there are many regions.
if (env.contains(point)) {
double[] result;
double x = point.getOrdinate(0);
double y = point.getOrdinate(1);
try {
result = region.evaluate(point, values);
// TODO It might be faster to put all the datums and Coverage regions into a spatial index instead of iterating.
for (VerticalDatum datum : datums) {
if (datum.covers(x, y)) {
result[0] += datum.interpolatedHeight(x, y);
return result;
}
}
// if we get here, all vdatums failed.
log.error("Failed to convert elevation at " + y + ", " + x + " from NAVD88 to NAD83");
} catch (PointOutsideCoverageException e) {
continue;
}
return result;
}
}
/* not found */
log.warn("Point not found: " + point);
return null;
}
Aggregations