Search in sources :

Example 21 with GridCoverage

use of org.opengis.coverage.grid.GridCoverage in project geowave by locationtech.

the class GeoWaveBasicCustomCRSRasterIT method queryNoDataMergeStrategy.

private void queryNoDataMergeStrategy(final String coverageName, final int tileSize) throws IOException {
    final DataStore dataStore = dataStoreOptions.createDataStore();
    try (CloseableIterator<?> it = dataStore.query(QueryBuilder.newBuilder().addTypeName(coverageName).build())) {
        // the expected outcome is:
        // band 1,2,3,4,5,6 has every value set correctly, band 0 has every
        // even row set correctly and every odd row should be NaN, and band
        // 7 has the upper quadrant as NaN and the rest set
        final GridCoverage coverage = (GridCoverage) it.next();
        final Raster raster = coverage.getRenderedImage().getData();
        Assert.assertEquals(tileSize, raster.getWidth(), DELTA);
        Assert.assertEquals(tileSize, raster.getHeight(), DELTA);
        for (int x = 0; x < tileSize; x++) {
            for (int y = 0; y < tileSize; y++) {
                for (int b = 1; b < 7; b++) {
                    Assert.assertEquals("x=" + x + ",y=" + y + ",b=" + b, TestUtils.getTileValue(x, y, b, tileSize), raster.getSampleDouble(x, y, b), DELTA);
                }
                if ((y % 2) == 0) {
                    Assert.assertEquals("x=" + x + ",y=" + y + ",b=0", TestUtils.getTileValue(x, y, 0, tileSize), raster.getSampleDouble(x, y, 0), DELTA);
                } else {
                    Assert.assertEquals("x=" + x + ",y=" + y + ",b=0", Double.NaN, raster.getSampleDouble(x, y, 0), DELTA);
                }
                if ((x > ((tileSize * 3) / 4)) && (y > ((tileSize * 3) / 4))) {
                    Assert.assertEquals("x=" + x + ",y=" + y + ",b=7", Double.NaN, raster.getSampleDouble(x, y, 7), DELTA);
                } else {
                    Assert.assertEquals("x=" + x + ",y=" + y + ",b=7", TestUtils.getTileValue(x, y, 7, tileSize), raster.getSampleDouble(x, y, 7), DELTA);
                }
            }
        }
        // there should be exactly one
        Assert.assertFalse(it.hasNext());
    }
}
Also used : GridCoverage(org.opengis.coverage.grid.GridCoverage) DataStore(org.locationtech.geowave.core.store.api.DataStore) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster)

Example 22 with GridCoverage

use of org.opengis.coverage.grid.GridCoverage in project georchestra by georchestra.

the class CoverageTransformation method perform.

/**
 * Entry point for performing a transformation
 *
 * @param in        the file to read the coverage from
 * @param transform the transformation to apply
 *
 * @return result from the transform object
 */
public static <T> T perform(File in, CoverageTransformation<T> transform) throws IOException {
    GeneralParameterValue[] params = new GeneralParameterValue[0];
    AbstractGridFormat gridFormat = lookupFormat(in);
    GridCoverage coverage = gridFormat.getReader(in).read(params);
    try {
        return transform.transform(coverage);
    } catch (FactoryException e) {
        throw new ExtractorException(e);
    }
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) GridCoverage(org.opengis.coverage.grid.GridCoverage) FactoryException(org.opengis.referencing.FactoryException) AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) ExtractorException(org.georchestra.extractorapp.ws.ExtractorException)

Aggregations

GridCoverage (org.opengis.coverage.grid.GridCoverage)22 RasterDataAdapter (org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter)9 Raster (java.awt.image.Raster)8 WritableRaster (java.awt.image.WritableRaster)8 DataStore (org.locationtech.geowave.core.store.api.DataStore)8 IOException (java.io.IOException)6 FitToIndexGridCoverage (org.locationtech.geowave.adapter.raster.FitToIndexGridCoverage)5 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)4 NoDataMergeStrategy (org.locationtech.geowave.adapter.raster.adapter.merge.nodata.NoDataMergeStrategy)4 Index (org.locationtech.geowave.core.store.api.Index)4 GeoWaveInputKey (org.locationtech.geowave.mapreduce.input.GeoWaveInputKey)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 AbstractGridFormat (org.geotools.coverage.grid.io.AbstractGridFormat)3 GeneralEnvelope (org.geotools.geometry.GeneralEnvelope)3 Point (org.locationtech.jts.geom.Point)3 Point (java.awt.Point)2 RenderedImage (java.awt.image.RenderedImage)2 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)2 Hints (org.geotools.util.factory.Hints)2