Search in sources :

Example 1 with StorageCountListener

use of org.geotoolkit.storage.StorageCountListener in project geotoolkit by Geomatys.

the class AggregatedCoverageResourceTest method testModifyAggregation.

/**
 * Test aggregating coverages one at the time.
 */
@Test
public void testModifyAggregation() throws DataStoreException, TransformException {
    // event counters
    StorageCountListener listener = new StorageCountListener();
    final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
    final GeneralEnvelope expected = new GeneralEnvelope(crs);
    final SampleDimension sd = new SampleDimension.Builder().setName("data").build();
    final List<SampleDimension> bands = Arrays.asList(sd);
    final GridGeometry grid1 = new GridGeometry(new GridExtent(3, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0.5, 0.5), crs);
    final GridGeometry grid2 = new GridGeometry(new GridExtent(3, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 1.5, 0.5), crs);
    final GridGeometry grid3 = new GridGeometry(new GridExtent(3, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 2.5, 0.5), 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 AggregatedCoverageResource agg = new AggregatedCoverageResource();
    agg.addListener(StoreEvent.class, listener);
    Assert.assertNull(agg.getEnvelope().orElse(null));
    agg.add(resource1);
    assertEquals(1, listener.count(ContentEvent.class));
    assertEquals(1, listener.count(ModelEvent.class));
    assertEquals(1, listener.count(AggregationEvent.class));
    Envelope envelope = agg.getEnvelope().orElse(null);
    expected.setRange(0, 0, 3);
    expected.setRange(1, 0, 1);
    assertEquals(expected, new GeneralEnvelope(envelope));
    agg.add(resource2);
    assertEquals(2, listener.count(ContentEvent.class));
    assertEquals(2, listener.count(ModelEvent.class));
    assertEquals(2, listener.count(AggregationEvent.class));
    envelope = agg.getEnvelope().orElse(null);
    expected.setRange(0, 0, 4);
    expected.setRange(1, 0, 1);
    assertEquals(expected, new GeneralEnvelope(envelope));
    agg.add(resource3);
    assertEquals(3, listener.count(ContentEvent.class));
    assertEquals(3, listener.count(ModelEvent.class));
    assertEquals(3, listener.count(AggregationEvent.class));
    envelope = agg.getEnvelope().orElse(null);
    expected.setRange(0, 0, 5);
    expected.setRange(1, 0, 1);
    assertEquals(expected, new GeneralEnvelope(envelope));
    agg.remove(resource1);
    agg.remove(resource2);
    assertEquals(5, listener.count(ContentEvent.class));
    assertEquals(5, listener.count(ModelEvent.class));
    assertEquals(5, listener.count(AggregationEvent.class));
    envelope = agg.getEnvelope().orElse(null);
    expected.setRange(0, 2, 5);
    expected.setRange(1, 0, 1);
    assertEquals(expected, new GeneralEnvelope(envelope));
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridExtent(org.apache.sis.coverage.grid.GridExtent) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) AggregationEvent(org.geotoolkit.storage.event.AggregationEvent) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) Envelope(org.opengis.geometry.Envelope) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) SampleDimension(org.apache.sis.coverage.SampleDimension) ModelEvent(org.geotoolkit.storage.event.ModelEvent) ContentEvent(org.geotoolkit.storage.event.ContentEvent) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) StorageCountListener(org.geotoolkit.storage.StorageCountListener) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) BufferedGridCoverage(org.apache.sis.coverage.grid.BufferedGridCoverage) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) Test(org.junit.Test)

Aggregations

SampleDimension (org.apache.sis.coverage.SampleDimension)1 BufferedGridCoverage (org.apache.sis.coverage.grid.BufferedGridCoverage)1 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)1 GridCoverageBuilder (org.apache.sis.coverage.grid.GridCoverageBuilder)1 GridExtent (org.apache.sis.coverage.grid.GridExtent)1 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)1 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)1 AffineTransform2D (org.apache.sis.internal.referencing.j2d.AffineTransform2D)1 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)1 StorageCountListener (org.geotoolkit.storage.StorageCountListener)1 AggregationEvent (org.geotoolkit.storage.event.AggregationEvent)1 ContentEvent (org.geotoolkit.storage.event.ContentEvent)1 ModelEvent (org.geotoolkit.storage.event.ModelEvent)1 InMemoryGridCoverageResource (org.geotoolkit.storage.memory.InMemoryGridCoverageResource)1 Test (org.junit.Test)1 Envelope (org.opengis.geometry.Envelope)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1