Search in sources :

Example 11 with InMemoryGridCoverageResource

use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.

the class AggregatedCoverageResourceTest method testResourceReadInError.

/**
 * Test fail safe when a resource fails a read operation.
 *
 * @throws DataStoreException
 * @throws TransformException
 */
@Test
public void testResourceReadInError() throws DataStoreException, TransformException {
    final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
    final SampleDimension sd = new SampleDimension.Builder().setName("data").build();
    final List<SampleDimension> bands = Arrays.asList(sd);
    /*
        Coverage 1
        +---+---+---+
        | 1 |NaN|NaN|
        +---+---+---+

        Coverage 2
        +---+---+---+
        | 2 | 2 |NaN| <-- will fail at reading time
        +---+---+---+

        Coverage 3
        +---+---+---+
        | 3 | 3 | 3 |
        +---+---+---+
        */
    final GridGeometry grid1 = new GridGeometry(new GridExtent(3, 1), PixelInCell.CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0, 0), crs);
    final GridCoverage coverage1 = new BufferedGridCoverage(grid1, bands, DataBuffer.TYPE_DOUBLE);
    final GridCoverage coverage2 = new BufferedGridCoverage(grid1, bands, DataBuffer.TYPE_DOUBLE);
    final GridCoverage coverage3 = new BufferedGridCoverage(grid1, bands, DataBuffer.TYPE_DOUBLE);
    final GridCoverageResource resource1 = new InMemoryGridCoverageResource(coverage1);
    final GridCoverageResource resource2 = new InMemoryGridCoverageResource(coverage2) {

        @Override
        public GridCoverage read(GridGeometry domain, int... range) throws DataStoreException {
            throw new RuntimeException("Read failing");
        }
    };
    final GridCoverageResource resource3 = new InMemoryGridCoverageResource(coverage3);
    final WritablePixelIterator write1 = WritablePixelIterator.create((WritableRenderedImage) coverage1.render(null));
    final WritablePixelIterator write2 = WritablePixelIterator.create((WritableRenderedImage) coverage2.render(null));
    final WritablePixelIterator write3 = WritablePixelIterator.create((WritableRenderedImage) coverage3.render(null));
    write1.moveTo(0, 0);
    write1.setSample(0, 1);
    write1.moveTo(1, 0);
    write1.setSample(0, Double.NaN);
    write1.moveTo(2, 0);
    write1.setSample(0, Double.NaN);
    write2.moveTo(0, 0);
    write2.setSample(0, 2);
    write2.moveTo(1, 0);
    write2.setSample(0, 2);
    write2.moveTo(2, 0);
    write2.setSample(0, Double.NaN);
    write3.moveTo(0, 0);
    write3.setSample(0, 3);
    write3.moveTo(1, 0);
    write3.setSample(0, 3);
    write3.moveTo(2, 0);
    write3.setSample(0, 3);
    /*
        We expect a final coverage with values [1,3,3] on a single row
        since 2 has failed reading
        +---+---+---+
        | 1 | 3 | 3 |
        +---+---+---+
        */
    final AggregatedCoverageResource aggregate = new AggregatedCoverageResource();
    aggregate.setInterpolation(Interpolation.NEAREST);
    aggregate.setMode(AggregatedCoverageResource.Mode.ORDER);
    aggregate.add(resource1);
    aggregate.add(resource2);
    aggregate.add(resource3);
    final double[] resolution = aggregate.getGridGeometry().getResolution(true);
    Assert.assertArrayEquals(new double[] { 1.0, 1.0 }, resolution, 0.0);
    final GridGeometry gridGeometry = aggregate.getGridGeometry();
    Assert.assertEquals(grid1, gridGeometry);
    final GridCoverage coverage = aggregate.read(grid1);
    final RenderedImage image = coverage.render(null);
    final PixelIterator reader = PixelIterator.create(image);
    reader.moveTo(0, 0);
    Assert.assertEquals(1, reader.getSample(0));
    reader.moveTo(1, 0);
    Assert.assertEquals(3, reader.getSample(0));
    reader.moveTo(2, 0);
    Assert.assertEquals(3, reader.getSample(0));
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridExtent(org.apache.sis.coverage.grid.GridExtent) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) PixelIterator(org.apache.sis.image.PixelIterator) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) SampleDimension(org.apache.sis.coverage.SampleDimension) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) WritableRenderedImage(java.awt.image.WritableRenderedImage) RenderedImage(java.awt.image.RenderedImage) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) Test(org.junit.Test)

Example 12 with InMemoryGridCoverageResource

use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.

the class AggregatedCoverageResourceTest method testModeScale.

/**
 * Test aggregation user order is preserved.
 *
 * @throws DataStoreException
 * @throws TransformException
 */
@Test
public void testModeScale() throws DataStoreException, TransformException {
    final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
    final SampleDimension sd = new SampleDimension.Builder().setName("data").setBackground(null, Double.NaN).build();
    final List<SampleDimension> bands = Arrays.asList(sd);
    /*
        Coverage 1
        +---+---+---+
        |NaN| 1 | 1 |
        +---+---+---+

        Coverage 2
        +---+---+---+---+---+---+
        |NaN|NaN| 2 | 2 |NaN|NaN|
        +---+---+---+---+---+---+
        |NaN|NaN| 2 | 2 |NaN|NaN|
        +---+---+---+---+---+---+

        Coverage 3
        +---+---+---+---+---+---+---+---+---+---+---+---+
        |NaN|NaN|NaN|NaN|NaN|NaN| 3 | 3 | 3 | 3 |NaN|NaN|
        +---+---+---+---+---+---+---+---+---+---+---+---+
        |NaN|NaN|NaN|NaN|NaN|NaN| 3 | 3 | 3 | 3 |NaN|NaN|
        +---+---+---+---+---+---+---+---+---+---+---+---+
        |NaN|NaN|NaN|NaN|NaN|NaN|NaN|NaN|NaN|NaN|NaN|NaN|
        +---+---+---+---+---+---+---+---+---+---+---+---+
        |NaN|NaN|NaN|NaN|NaN|NaN|NaN|NaN|NaN|NaN|NaN|NaN|
        +---+---+---+---+---+---+---+---+---+---+---+---+
        */
    final GridGeometry grid1 = new GridGeometry(new GridExtent(3, 1), CELL_CENTER, new AffineTransform2D(2.0, 0, 0, 2.0, 1.00, 1.00), crs);
    final GridGeometry grid2 = new GridGeometry(new GridExtent(6, 2), CELL_CENTER, new AffineTransform2D(1.0, 0, 0, 1.0, 0.50, 0.50), crs);
    final GridGeometry grid3 = new GridGeometry(new GridExtent(12, 4), CELL_CENTER, new AffineTransform2D(0.5, 0, 0, 0.5, 0.25, 0.25), crs);
    final GridCoverage coverage1 = new BufferedGridCoverage(grid1, bands, DataBuffer.TYPE_DOUBLE);
    final GridCoverage coverage2 = new BufferedGridCoverage(grid2, bands, DataBuffer.TYPE_DOUBLE);
    final GridCoverage coverage3 = new BufferedGridCoverage(grid3, bands, DataBuffer.TYPE_DOUBLE);
    final GridCoverageResource resource1 = new InMemoryGridCoverageResource(coverage1);
    final GridCoverageResource resource2 = new InMemoryGridCoverageResource(coverage2);
    final GridCoverageResource resource3 = new InMemoryGridCoverageResource(coverage3);
    final WritableRenderedImage img1 = (WritableRenderedImage) coverage1.render(null);
    final WritableRenderedImage img2 = (WritableRenderedImage) coverage2.render(null);
    final WritableRenderedImage img3 = (WritableRenderedImage) coverage3.render(null);
    final WritablePixelIterator write1 = WritablePixelIterator.create(img1);
    final WritablePixelIterator write2 = WritablePixelIterator.create(img2);
    final WritablePixelIterator write3 = WritablePixelIterator.create(img3);
    BufferedImages.setAll(img1, new double[] { Double.NaN });
    BufferedImages.setAll(img2, new double[] { Double.NaN });
    BufferedImages.setAll(img3, new double[] { Double.NaN });
    write1.moveTo(1, 0);
    write1.setSample(0, 1);
    write1.moveTo(2, 0);
    write1.setSample(0, 1);
    write2.moveTo(2, 0);
    write2.setSample(0, 2);
    write2.moveTo(3, 0);
    write2.setSample(0, 2);
    write2.moveTo(2, 1);
    write2.setSample(0, 2);
    write2.moveTo(3, 1);
    write2.setSample(0, 2);
    write3.moveTo(6, 0);
    write3.setSample(0, 3);
    write3.moveTo(7, 0);
    write3.setSample(0, 3);
    write3.moveTo(8, 0);
    write3.setSample(0, 3);
    write3.moveTo(9, 0);
    write3.setSample(0, 3);
    write3.moveTo(6, 1);
    write3.setSample(0, 3);
    write3.moveTo(7, 1);
    write3.setSample(0, 3);
    write3.moveTo(8, 1);
    write3.setSample(0, 3);
    write3.moveTo(9, 1);
    write3.setSample(0, 3);
    /*
        We expect a final coverage to be :

        +---+---+---+---+---+---+
        |NaN|NaN| 2 | 2 | 3 | 1 |
        +---+---+---+---+---+---+
        |NaN|NaN| 2 | 2 | 1 | 1 |
        +---+---+---+---+---+---+
        */
    final AggregatedCoverageResource aggregate = new AggregatedCoverageResource();
    aggregate.setInterpolation(Interpolation.NEAREST);
    aggregate.setMode(AggregatedCoverageResource.Mode.SCALE);
    aggregate.add(resource1);
    aggregate.add(resource2);
    aggregate.add(resource3);
    // we must obtain the lowest resolution
    final double[] resolution = aggregate.getGridGeometry().getResolution(true);
    Assert.assertArrayEquals(new double[] { 0.5, 0.5 }, resolution, 0.0);
    final GridGeometry gridGeometry = aggregate.getGridGeometry();
    Assert.assertTrue(!gridGeometry.isDefined(GridGeometry.EXTENT));
    Assert.assertTrue(gridGeometry.isDefined(GridGeometry.ENVELOPE));
    final GridCoverage coverage = aggregate.read(grid2);
    final RenderedImage image = coverage.render(null);
    final PixelIterator reader = PixelIterator.create(image);
    reader.moveTo(0, 0);
    Assert.assertTrue(Double.isNaN(reader.getSampleDouble(0)));
    reader.moveTo(1, 0);
    Assert.assertTrue(Double.isNaN(reader.getSampleDouble(0)));
    reader.moveTo(2, 0);
    assertEquals(2, reader.getSample(0));
    reader.moveTo(3, 0);
    assertEquals(2, reader.getSample(0));
    reader.moveTo(4, 0);
    assertEquals(3, reader.getSample(0));
    reader.moveTo(5, 0);
    assertEquals(1, reader.getSample(0));
    reader.moveTo(0, 1);
    Assert.assertTrue(Double.isNaN(reader.getSampleDouble(0)));
    reader.moveTo(1, 1);
    Assert.assertTrue(Double.isNaN(reader.getSampleDouble(0)));
    reader.moveTo(2, 1);
    assertEquals(2, reader.getSample(0));
    reader.moveTo(3, 1);
    assertEquals(2, reader.getSample(0));
    reader.moveTo(4, 1);
    assertEquals(1, reader.getSample(0));
    reader.moveTo(5, 1);
    assertEquals(1, reader.getSample(0));
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridExtent(org.apache.sis.coverage.grid.GridExtent) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) PixelIterator(org.apache.sis.image.PixelIterator) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) SampleDimension(org.apache.sis.coverage.SampleDimension) WritableRenderedImage(java.awt.image.WritableRenderedImage) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) WritableRenderedImage(java.awt.image.WritableRenderedImage) RenderedImage(java.awt.image.RenderedImage) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) Test(org.junit.Test)

Example 13 with InMemoryGridCoverageResource

use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.

the class AggregatedCoverageResourceTest method testNoDataAdded.

/**
 * Test aggregation add a NaN value to fill spaces.
 *
 * @throws DataStoreException
 * @throws TransformException
 */
@Test
public void testNoDataAdded() throws DataStoreException, TransformException {
    final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
    final SampleDimension sd = new SampleDimension.Builder().setName("data").setBackground("no-data", Short.MIN_VALUE).build();
    final List<SampleDimension> bands = Arrays.asList(sd);
    /*
        Coverage 1
        +---+
        | 1 |
        +---+

        Coverage 2
                +---+
                | 2 |
                +---+

        */
    final GridGeometry grid1 = new GridGeometry(new GridExtent(1, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0, 0), crs);
    final GridGeometry grid2 = new GridGeometry(new GridExtent(1, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 2, 0), crs);
    final GridGeometry grid = new GridGeometry(new GridExtent(3, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0, 0), crs);
    final GridCoverage coverage1 = new BufferedGridCoverage(grid1, bands, DataBuffer.TYPE_SHORT);
    final GridCoverage coverage2 = new BufferedGridCoverage(grid2, bands, DataBuffer.TYPE_SHORT);
    final GridCoverageResource resource1 = new InMemoryGridCoverageResource(coverage1);
    final GridCoverageResource resource2 = new InMemoryGridCoverageResource(coverage2);
    final WritablePixelIterator write1 = WritablePixelIterator.create((WritableRenderedImage) coverage1.render(null));
    final WritablePixelIterator write2 = WritablePixelIterator.create((WritableRenderedImage) coverage2.render(null));
    write1.moveTo(0, 0);
    write1.setSample(0, 1);
    write2.moveTo(0, 0);
    write2.setSample(0, 2);
    /*
        We expect a final coverage with values :
        +---+------+---+
        | 1 |-32768| 2 |
        +---+------+---+
        */
    final GridCoverageResource aggregate = AggregatedCoverageResource.create(null, AggregatedCoverageResource.Mode.ORDER, resource1, resource2);
    ((AggregatedCoverageResource) aggregate).setInterpolation(Interpolation.NEAREST);
    final GridGeometry gridGeometry = aggregate.getGridGeometry();
    Assert.assertTrue(!gridGeometry.isDefined(GridGeometry.EXTENT));
    Assert.assertTrue(gridGeometry.isDefined(GridGeometry.ENVELOPE));
    final GridCoverage coverage = aggregate.read(grid).forConvertedValues(true);
    final RenderedImage image = coverage.render(null);
    final PixelIterator reader = PixelIterator.create(image);
    reader.moveTo(0, 0);
    assertEquals(1, reader.getSample(0));
    reader.moveTo(1, 0);
    assertEquals(Short.MIN_VALUE, reader.getSample(0));
    reader.moveTo(2, 0);
    assertEquals(2, reader.getSample(0));
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridExtent(org.apache.sis.coverage.grid.GridExtent) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) PixelIterator(org.apache.sis.image.PixelIterator) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) SampleDimension(org.apache.sis.coverage.SampleDimension) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) WritableRenderedImage(java.awt.image.WritableRenderedImage) RenderedImage(java.awt.image.RenderedImage) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) Test(org.junit.Test)

Example 14 with InMemoryGridCoverageResource

use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.

the class AggregatedCoverageResourceTest method testModeOrder.

/**
 * Test aggregation user order is preserved.
 *
 * @throws DataStoreException
 * @throws TransformException
 */
@Test
public void testModeOrder() throws DataStoreException, TransformException {
    final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
    final SampleDimension sd = new SampleDimension.Builder().setName("data").build();
    final List<SampleDimension> bands = Arrays.asList(sd);
    /*
        Coverage 1
        +---+---+---+
        | 1 |NaN|NaN|
        +---+---+---+

        Coverage 2
        +---+---+---+
        | 2 | 2 |NaN|
        +---+---+---+

        Coverage 3
        +---+---+---+
        | 3 | 3 | 3 |
        +---+---+---+
        */
    final GridGeometry grid1 = new GridGeometry(new GridExtent(3, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0, 0), crs);
    final GridCoverage coverage1 = new BufferedGridCoverage(grid1, bands, DataBuffer.TYPE_DOUBLE);
    final GridCoverage coverage2 = new BufferedGridCoverage(grid1, bands, DataBuffer.TYPE_DOUBLE);
    final GridCoverage coverage3 = new BufferedGridCoverage(grid1, bands, DataBuffer.TYPE_DOUBLE);
    final GridCoverageResource resource1 = new InMemoryGridCoverageResource(coverage1);
    final GridCoverageResource resource2 = new InMemoryGridCoverageResource(coverage2);
    final GridCoverageResource resource3 = new InMemoryGridCoverageResource(coverage3);
    final WritablePixelIterator write1 = WritablePixelIterator.create((WritableRenderedImage) coverage1.render(null));
    final WritablePixelIterator write2 = WritablePixelIterator.create((WritableRenderedImage) coverage2.render(null));
    final WritablePixelIterator write3 = WritablePixelIterator.create((WritableRenderedImage) coverage3.render(null));
    write1.moveTo(0, 0);
    write1.setSample(0, 1);
    write1.moveTo(1, 0);
    write1.setSample(0, Double.NaN);
    write1.moveTo(2, 0);
    write1.setSample(0, Double.NaN);
    write2.moveTo(0, 0);
    write2.setSample(0, 2);
    write2.moveTo(1, 0);
    write2.setSample(0, 2);
    write2.moveTo(2, 0);
    write2.setSample(0, Double.NaN);
    write3.moveTo(0, 0);
    write3.setSample(0, 3);
    write3.moveTo(1, 0);
    write3.setSample(0, 3);
    write3.moveTo(2, 0);
    write3.setSample(0, 3);
    /*
        We expect a final coverage with values [1,2,3] on a single row
        +---+---+---+
        | 1 | 2 | 3 |
        +---+---+---+
        */
    final AggregatedCoverageResource aggregate = new AggregatedCoverageResource();
    aggregate.setInterpolation(Interpolation.NEAREST);
    aggregate.setMode(AggregatedCoverageResource.Mode.ORDER);
    aggregate.add(resource1);
    aggregate.add(resource2);
    aggregate.add(resource3);
    final double[] resolution = aggregate.getGridGeometry().getResolution(true);
    Assert.assertArrayEquals(new double[] { 1.0, 1.0 }, resolution, 0.0);
    final GridGeometry gridGeometry = aggregate.getGridGeometry();
    assertEquals(grid1, gridGeometry);
    final GridCoverage coverage = aggregate.read(grid1);
    final RenderedImage image = coverage.render(null);
    final PixelIterator reader = PixelIterator.create(image);
    reader.moveTo(0, 0);
    assertEquals(1, reader.getSample(0));
    reader.moveTo(1, 0);
    assertEquals(2, reader.getSample(0));
    reader.moveTo(2, 0);
    assertEquals(3, reader.getSample(0));
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridExtent(org.apache.sis.coverage.grid.GridExtent) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) PixelIterator(org.apache.sis.image.PixelIterator) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) SampleDimension(org.apache.sis.coverage.SampleDimension) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) WritableRenderedImage(java.awt.image.WritableRenderedImage) RenderedImage(java.awt.image.RenderedImage) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) Test(org.junit.Test)

Example 15 with InMemoryGridCoverageResource

use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.

the class TiledCoverageResourceTest method testNoDataAdded.

/**
 * Test mosaic add a NaN value to fill spaces.
 */
@Test
public void testNoDataAdded() throws IOException, DataStoreException, TransformException {
    final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
    final SampleDimension sd = new SampleDimension.Builder().setName("data").build();
    final List<SampleDimension> bands = Arrays.asList(sd);
    /*
        Coverage 1
        +---+
        | 1 |
        +---+

        Coverage 2
                +---+
                | 2 |
                +---+

        */
    final GridGeometry grid1 = new GridGeometry(new GridExtent(1, 1), PixelInCell.CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0, 0), crs);
    final GridGeometry grid2 = new GridGeometry(new GridExtent(1, 1), PixelInCell.CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 2, 0), crs);
    final GridGeometry grid = new GridGeometry(new GridExtent(3, 1), PixelInCell.CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0, 0), crs);
    final GridCoverage coverage1 = new BufferedGridCoverage(grid1, bands, DataBuffer.TYPE_SHORT);
    final GridCoverage coverage2 = new BufferedGridCoverage(grid2, bands, DataBuffer.TYPE_SHORT);
    final GridCoverageResource resource1 = new InMemoryGridCoverageResource(coverage1);
    final GridCoverageResource resource2 = new InMemoryGridCoverageResource(coverage2);
    final WritablePixelIterator write1 = WritablePixelIterator.create((WritableRenderedImage) coverage1.render(null));
    final WritablePixelIterator write2 = WritablePixelIterator.create((WritableRenderedImage) coverage2.render(null));
    write1.moveTo(0, 0);
    write1.setSample(0, 1);
    write2.moveTo(0, 0);
    write2.setSample(0, 2);
    /*
        We expect a final coverage with values :
        +---+---+---+
        | 1 |NaN| 2 |
        +---+---+---+
        */
    final GridCoverageResource aggregate = TiledCoverageResource.create(resource1, resource2).get(0);
    final GridCoverage coverage = aggregate.read(grid).forConvertedValues(true);
    final RenderedImage image = coverage.render(null);
    final PixelIterator reader = PixelIterator.create(image);
    reader.moveTo(0, 0);
    Assert.assertEquals(1, reader.getSampleDouble(0), 0.0);
    reader.moveTo(1, 0);
    Assert.assertEquals(Double.NaN, reader.getSampleDouble(0), 0.0);
    reader.moveTo(2, 0);
    Assert.assertEquals(2, reader.getSampleDouble(0), 0.0);
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridExtent(org.apache.sis.coverage.grid.GridExtent) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) PixelIterator(org.apache.sis.image.PixelIterator) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) SampleDimension(org.apache.sis.coverage.SampleDimension) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) RenderedImage(java.awt.image.RenderedImage) WritableRenderedImage(java.awt.image.WritableRenderedImage) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) Test(org.junit.Test)

Aggregations

InMemoryGridCoverageResource (org.geotoolkit.storage.memory.InMemoryGridCoverageResource)38 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)34 Test (org.junit.Test)33 GridExtent (org.apache.sis.coverage.grid.GridExtent)32 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)32 SampleDimension (org.apache.sis.coverage.SampleDimension)28 AffineTransform2D (org.apache.sis.internal.referencing.j2d.AffineTransform2D)27 GridCoverageBuilder (org.apache.sis.coverage.grid.GridCoverageBuilder)26 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)25 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)22 RenderedImage (java.awt.image.RenderedImage)18 BufferedGridCoverage (org.apache.sis.coverage.grid.BufferedGridCoverage)17 WritableRenderedImage (java.awt.image.WritableRenderedImage)16 PixelIterator (org.apache.sis.image.PixelIterator)15 WritablePixelIterator (org.apache.sis.image.WritablePixelIterator)15 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)14 BufferedImage (java.awt.image.BufferedImage)13 Graphics2D (java.awt.Graphics2D)6 GridCoverage2D (org.apache.sis.coverage.grid.GridCoverage2D)6 FeatureSet (org.apache.sis.storage.FeatureSet)6