Search in sources :

Example 1 with PointOutsideCoverageException

use of org.opengis.coverage.PointOutsideCoverageException 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

AbstractCoverage (org.geotools.coverage.AbstractCoverage)1 GeneralEnvelope (org.geotools.geometry.GeneralEnvelope)1 Coverage (org.opengis.coverage.Coverage)1 PointOutsideCoverageException (org.opengis.coverage.PointOutsideCoverageException)1