Search in sources :

Example 1 with BufferedGridCoverage

use of org.apache.sis.coverage.grid.BufferedGridCoverage in project geotoolkit by Geomatys.

the class AggregatedCoverageResourceTest method testResourceMetaInError.

/**
 * Test fail safe when a resource fails on metadatas and read operation.
 *
 * @throws DataStoreException
 * @throws TransformException
 */
@Test
public void testResourceMetaInError() 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 metadata and 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 GridGeometry getGridGeometry() throws DataStoreException {
            throw new RuntimeException("Metadata failing");
        }

        @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 2 with BufferedGridCoverage

use of org.apache.sis.coverage.grid.BufferedGridCoverage in project geotoolkit by Geomatys.

the class AggregatedCoverageResourceTest method testSampleTransform.

/**
 * Test sample transform is applied and NaN value is evaluated after transform.
 */
@Test
public void testSampleTransform() 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 | -5 |NaN|
        +---+---+---+

        Coverage 3
        +---+---+---+
        | 3 | 3 | 0 |
        +---+---+---+
        */
    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, -5);
    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, 0);
    /*
        We expect a final coverage with values [1,2,3] on a single row
        +---+---+---+
        | 12 |-3|NaN|
        +---+---+---+
        */
    final MathTransform1D trs1 = new AbstractMathTransform1D() {

        @Override
        public double transform(double value) throws TransformException {
            return value * 12.0;
        }

        @Override
        public double derivative(double value) throws TransformException {
            throw new TransformException("Not supported.");
        }
    };
    final MathTransform1D trs2 = new AbstractMathTransform1D() {

        @Override
        public double transform(double value) throws TransformException {
            return value < 0 ? Double.NaN : value;
        }

        @Override
        public double derivative(double value) throws TransformException {
            throw new TransformException("Not supported.");
        }
    };
    final MathTransform1D trs3 = new AbstractMathTransform1D() {

        @Override
        public double transform(double value) throws TransformException {
            return value > 0 ? -value : Double.NaN;
        }

        @Override
        public double derivative(double value) throws TransformException {
            throw new TransformException("Not supported.");
        }
    };
    final AggregatedCoverageResource.VirtualBand band = new AggregatedCoverageResource.VirtualBand();
    final AggregatedCoverageResource.Source source1 = new AggregatedCoverageResource.Source(resource1, 0, trs1);
    final AggregatedCoverageResource.Source source2 = new AggregatedCoverageResource.Source(resource2, 0, trs2);
    final AggregatedCoverageResource.Source source3 = new AggregatedCoverageResource.Source(resource3, 0, trs3);
    band.setSources(source1, source2, source3);
    final AggregatedCoverageResource aggregate = new AggregatedCoverageResource(Collections.singletonList(band), AggregatedCoverageResource.Mode.ORDER, null);
    aggregate.setInterpolation(Interpolation.NEAREST);
    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(12.0, reader.getSampleDouble(0), 0.0);
    reader.moveTo(1, 0);
    assertEquals(-3.0, reader.getSampleDouble(0), 0.0);
    reader.moveTo(2, 0);
    assertEquals(Double.NaN, 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) AbstractMathTransform1D(org.apache.sis.referencing.operation.transform.AbstractMathTransform1D) PixelIterator(org.apache.sis.image.PixelIterator) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) TransformException(org.opengis.referencing.operation.TransformException) 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) AbstractMathTransform1D(org.apache.sis.referencing.operation.transform.AbstractMathTransform1D) MathTransform1D(org.opengis.referencing.operation.MathTransform1D) 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 3 with BufferedGridCoverage

use of org.apache.sis.coverage.grid.BufferedGridCoverage 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 4 with BufferedGridCoverage

use of org.apache.sis.coverage.grid.BufferedGridCoverage 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 5 with BufferedGridCoverage

use of org.apache.sis.coverage.grid.BufferedGridCoverage 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)

Aggregations

SampleDimension (org.apache.sis.coverage.SampleDimension)18 BufferedGridCoverage (org.apache.sis.coverage.grid.BufferedGridCoverage)18 GridExtent (org.apache.sis.coverage.grid.GridExtent)18 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)18 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)17 AffineTransform2D (org.apache.sis.internal.referencing.j2d.AffineTransform2D)17 Test (org.junit.Test)17 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)17 InMemoryGridCoverageResource (org.geotoolkit.storage.memory.InMemoryGridCoverageResource)16 RenderedImage (java.awt.image.RenderedImage)15 WritableRenderedImage (java.awt.image.WritableRenderedImage)15 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)15 GridCoverageBuilder (org.apache.sis.coverage.grid.GridCoverageBuilder)14 PixelIterator (org.apache.sis.image.PixelIterator)14 WritablePixelIterator (org.apache.sis.image.WritablePixelIterator)14 DataBufferInt (java.awt.image.DataBufferInt)2 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)2 DefaultCartesianCS (org.apache.sis.referencing.cs.DefaultCartesianCS)2 DefaultCoordinateSystemAxis (org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis)2 DefaultImageDatum (org.apache.sis.referencing.datum.DefaultImageDatum)2