Search in sources :

Example 1 with Coverage

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);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Coverage(org.opengis.coverage.Coverage) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) ElevationPoint(org.opentripplanner.graph_builder.module.extra_elevation_data.ElevationPoint) StreetWithElevationEdge(org.opentripplanner.routing.edgetype.StreetWithElevationEdge) ElevationPoint(org.opentripplanner.graph_builder.module.extra_elevation_data.ElevationPoint) InterpolationBilinear(javax.media.jai.InterpolationBilinear) StreetWithElevationEdge(org.opentripplanner.routing.edgetype.StreetWithElevationEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 2 with Coverage

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;
}
Also used : PointOutsideCoverageException(org.opengis.coverage.PointOutsideCoverageException) AbstractCoverage(org.geotools.coverage.AbstractCoverage) Coverage(org.opengis.coverage.Coverage) GeneralEnvelope(org.geotools.geometry.GeneralEnvelope)

Aggregations

Coverage (org.opengis.coverage.Coverage)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 InterpolationBilinear (javax.media.jai.InterpolationBilinear)1 AbstractCoverage (org.geotools.coverage.AbstractCoverage)1 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)1 GeneralEnvelope (org.geotools.geometry.GeneralEnvelope)1 PointOutsideCoverageException (org.opengis.coverage.PointOutsideCoverageException)1 ElevationPoint (org.opentripplanner.graph_builder.module.extra_elevation_data.ElevationPoint)1 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)1 StreetWithElevationEdge (org.opentripplanner.routing.edgetype.StreetWithElevationEdge)1 Edge (org.opentripplanner.routing.graph.Edge)1 Vertex (org.opentripplanner.routing.graph.Vertex)1