Search in sources :

Example 1 with GeneralEnvelope

use of org.geotools.geometry.GeneralEnvelope in project polymap4-core by Polymap4.

the class RasterRenderProcessor method getBoundsRequest.

@Override
public void getBoundsRequest(GetBoundsRequest request, ProcessorContext context) throws Exception {
    GeneralEnvelope envelope = reader.getOriginalEnvelope();
    if (envelope != null) {
        context.sendResponse(new GetBoundsResponse(new ReferencedEnvelope(envelope)));
        return;
    }
    CoordinateReferenceSystem crs = reader.getCoordinateReferenceSystem();
    if (crs != null) {
        context.sendResponse(new GetBoundsResponse(new ReferencedEnvelope(crs)));
        return;
    }
    throw new IllegalStateException("No bounds founds.");
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) GetBoundsResponse(org.polymap.core.data.feature.GetBoundsResponse) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeneralEnvelope(org.geotools.geometry.GeneralEnvelope)

Example 2 with GeneralEnvelope

use of org.geotools.geometry.GeneralEnvelope 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

GeneralEnvelope (org.geotools.geometry.GeneralEnvelope)2 AbstractCoverage (org.geotools.coverage.AbstractCoverage)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 Coverage (org.opengis.coverage.Coverage)1 PointOutsideCoverageException (org.opengis.coverage.PointOutsideCoverageException)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 GetBoundsResponse (org.polymap.core.data.feature.GetBoundsResponse)1