Search in sources :

Example 1 with InterpolationBilinear

use of javax.media.jai.InterpolationBilinear 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 InterpolationBilinear

use of javax.media.jai.InterpolationBilinear in project sldeditor by robward-scisys.

the class InterpolationValues method setValue.

/*
     * (non-Javadoc)
     *
     * @see
     * com.sldeditor.rendertransformation.types.RenderTransformValueInterface#setValue(java.lang.
     * Object)
     */
@Override
public void setValue(Object aValue) {
    this.value = null;
    this.expression = null;
    if (aValue instanceof LiteralExpressionImpl) {
        String displayName = ((Expression) aValue).toString();
        if (InterpolationNearest.class.getSimpleName().compareTo(displayName) == 0) {
            value = new InterpolationNearest();
        } else if (InterpolationBilinear.class.getSimpleName().compareTo(displayName) == 0) {
            value = new InterpolationBilinear();
        } else if (displayName.startsWith(InterpolationBicubic2.class.getSimpleName())) {
            sampleBits = extractSampleBits(INTERPOLATION_BICUBIC2_PATTERN_MATCH, displayName);
            value = new InterpolationBicubic2(sampleBits);
        } else if (displayName.startsWith(InterpolationBicubic.class.getSimpleName())) {
            sampleBits = extractSampleBits(INTERPOLATION_BICUBIC_PATTERN_MATCH, displayName);
            value = new InterpolationBicubic(sampleBits);
        }
    } else if ((aValue instanceof AttributeExpressionImpl) || (aValue instanceof FunctionExpressionImpl) || (aValue instanceof MathExpressionImpl)) {
        this.expression = (Expression) aValue;
    }
}
Also used : InterpolationBicubic(javax.media.jai.InterpolationBicubic) InterpolationNearest(javax.media.jai.InterpolationNearest) InterpolationBicubic2(javax.media.jai.InterpolationBicubic2) MathExpressionImpl(org.geotools.filter.MathExpressionImpl) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) InterpolationBilinear(javax.media.jai.InterpolationBilinear) FunctionExpressionImpl(org.geotools.filter.FunctionExpressionImpl)

Example 3 with InterpolationBilinear

use of javax.media.jai.InterpolationBilinear in project OpenTripPlanner by opentripplanner.

the class NEDGridCoverageFactoryImpl method getGridCoverage.

/**
 * @return a GeoTools grid coverage for the entire area of interest, lazy-creating it on the first call.
 */
public Coverage getGridCoverage() {
    if (unifiedCoverage == null) {
        loadVerticalDatum();
        tileSource.setGraph(graph);
        tileSource.setCacheDirectory(cacheDirectory);
        List<File> paths = tileSource.getNEDTiles();
        // Make one grid coverage for each NED tile, adding them all to a single UnifiedGridCoverage.
        for (File path : paths) {
            GeotiffGridCoverageFactoryImpl factory = new GeotiffGridCoverageFactoryImpl(path);
            // TODO might bicubic interpolation give better results?
            GridCoverage2D regionCoverage = Interpolator2D.create(factory.getGridCoverage(), new InterpolationBilinear());
            if (unifiedCoverage == null) {
                unifiedCoverage = new UnifiedGridCoverage("unified", regionCoverage, datums);
            } else {
                unifiedCoverage.add(regionCoverage);
            }
        }
    }
    return unifiedCoverage;
}
Also used : GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) InterpolationBilinear(javax.media.jai.InterpolationBilinear) File(java.io.File)

Aggregations

InterpolationBilinear (javax.media.jai.InterpolationBilinear)3 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 InterpolationBicubic (javax.media.jai.InterpolationBicubic)1 InterpolationBicubic2 (javax.media.jai.InterpolationBicubic2)1 InterpolationNearest (javax.media.jai.InterpolationNearest)1 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)1 FunctionExpressionImpl (org.geotools.filter.FunctionExpressionImpl)1 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)1 MathExpressionImpl (org.geotools.filter.MathExpressionImpl)1 Coverage (org.opengis.coverage.Coverage)1 Expression (org.opengis.filter.expression.Expression)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