use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class IsolineSymbolizerRenderer method presentations.
@Override
public Stream<Presentation> presentations(MapLayer layer, Resource resource) {
if (!(resource instanceof GridCoverageResource)) {
return Stream.empty();
}
final GridCoverageResource coverageReference = (GridCoverageResource) resource;
final IsolineSymbolizer isolineSymbolizer = symbol.getSource();
try {
Stream<Presentation> stream = Stream.empty();
// //////////////////
// 1 - Render raster
// //////////////////
final CachedRasterSymbolizer cachedRasterSymbolizer = symbol.getCachedRasterSymbolizer();
if (!isolineSymbolizer.getIsolineOnly() || isJenksFunction(cachedRasterSymbolizer)) {
final MapLayer sublayer = MapBuilder.createLayer(coverageReference);
sublayer.setStyle(GO2Utilities.STYLE_FACTORY.style(cachedRasterSymbolizer.getSource()));
stream = Stream.concat(stream, DefaultPortrayalService.present(sublayer, coverageReference, renderingContext));
}
final LineSymbolizer lineSymbolizer = isolineSymbolizer.getLineSymbolizer();
final TextSymbolizer textSymbolizer = isolineSymbolizer.getTextSymbolizer();
// //////////////////
if (lineSymbolizer != null) {
double[] intervales = symbol.getSteps();
final CoverageQuery query = new CoverageQuery();
query.setSelection(renderingContext.getGridGeometry());
query.setSourceDomainExpansion(2);
final GridCoverageResource res = coverageReference.subset(query);
final GridCoverage inCoverage = res.read(null).forConvertedValues(true);
final GridCoverageResource resampledCovRef = new InMemoryGridCoverageResource(coverageReference.getIdentifier().orElse(null), inCoverage);
// ///////////////////
// 2.2 - Compute isolines
// //////////////////
FeatureSet isolines = null;
final ProcessDescriptor isolineDesc = symbol.getIsolineDesc();
if (isolineDesc != null) {
final Parameters inputs = Parameters.castOrWrap(isolineDesc.getInputDescriptor().createValue());
inputs.getOrCreate(IsolineDescriptor.COVERAGE_REF).setValue(resampledCovRef);
inputs.getOrCreate(IsolineDescriptor.INTERVALS).setValue(intervales);
final org.geotoolkit.process.Process process = isolineDesc.createProcess(inputs);
final ParameterValueGroup result = process.call();
isolines = (FeatureSet) result.parameter(IsolineDescriptor.FCOLL.getName().getCode()).getValue();
}
// //////////////////
if (isolines != null) {
MutableStyle featureStyle = null;
if (textSymbolizer != null) {
featureStyle = GO2Utilities.STYLE_FACTORY.style(lineSymbolizer, textSymbolizer);
} else {
featureStyle = GO2Utilities.STYLE_FACTORY.style(lineSymbolizer);
}
MapLayer fml = MapBuilder.createLayer(isolines);
fml.setStyle(featureStyle);
stream = Stream.concat(stream, DefaultPortrayalService.present(fml, isolines, renderingContext));
}
}
return stream;
} catch (DataStoreException | ProcessException ex) {
ExceptionPresentation ep = new ExceptionPresentation(ex);
ep.setLayer(layer);
ep.setResource(resource);
return Stream.of(ep);
}
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource 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));
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class AggregatedCoverageResourceTest method testModeOrderRGB.
/**
* Test aggregation user order is preserved with RGB images.
*
* @throws DataStoreException
* @throws TransformException
*/
@Test
public void testModeOrderRGB() 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
+---+---+---+
| R |NaN|NaN|
+---+---+---+
Coverage 2
+---+---+---+
| G | G |NaN|
+---+---+---+
Coverage 3
+---+---+---+
| B | B | B |
+---+---+---+
*/
final GridGeometry grid1 = new GridGeometry(new GridExtent(3, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0, 0), crs);
final BufferedImage image1 = new BufferedImage(3, 1, BufferedImage.TYPE_INT_ARGB);
final BufferedImage image2 = new BufferedImage(3, 1, BufferedImage.TYPE_INT_ARGB);
final BufferedImage image3 = new BufferedImage(3, 1, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g1 = image1.createGraphics();
final Graphics2D g2 = image2.createGraphics();
final Graphics2D g3 = image3.createGraphics();
g1.setPaint(Color.RED);
g2.setPaint(Color.GREEN);
g3.setPaint(Color.BLUE);
g1.fillRect(0, 0, 1, 1);
g2.fillRect(0, 0, 2, 1);
g3.fillRect(0, 0, 3, 1);
final GridCoverage coverage1 = new GridCoverageBuilder().setDomain(grid1).setValues(image1).build();
final GridCoverage coverage2 = new GridCoverageBuilder().setDomain(grid1).setValues(image2).build();
final GridCoverage coverage3 = new GridCoverageBuilder().setDomain(grid1).setValues(image3).build();
final GridCoverageResource resource1 = new InMemoryGridCoverageResource(coverage1);
final GridCoverageResource resource2 = new InMemoryGridCoverageResource(coverage2);
final GridCoverageResource resource3 = new InMemoryGridCoverageResource(coverage3);
/*
We expect a final coverage with values [R,G,B] on a single row
+---+---+---+
| R | G | B |
+---+---+---+
*/
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);
Assert.assertArrayEquals(new double[] { 255.0, 0.0, 0.0, 255.0 }, reader.getPixel((double[]) null), 0.0);
reader.moveTo(1, 0);
Assert.assertArrayEquals(new double[] { 0.0, 255.0, 0.0, 255.0 }, reader.getPixel((double[]) null), 0.0);
reader.moveTo(2, 0);
Assert.assertArrayEquals(new double[] { 0.0, 0.0, 255.0, 255.0 }, reader.getPixel((double[]) null), 0.0);
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class AggregatedCoverageResourceTest method testMultiBandAggregation.
/**
* Test aggregating coverages with multiple sample dimensions.
*/
@Test
public void testMultiBandAggregation() 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, sd);
/*
Coverage 1
+---+---+---+
|1:2|NaN|NaN|
+---+---+---+
Coverage 2
+---+---+---+
|3:4|3:4|NaN|
+---+---+---+
Coverage 3
+---+---+---+
|5:6|5:6|5:6|
+---+---+---+
*/
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.setPixel(new double[] { 1, 2 });
write1.moveTo(1, 0);
write1.setPixel(new double[] { Double.NaN, Double.NaN });
write1.moveTo(2, 0);
write1.setPixel(new double[] { Double.NaN, Double.NaN });
write2.moveTo(0, 0);
write2.setPixel(new double[] { 3, 4 });
write2.moveTo(1, 0);
write2.setPixel(new double[] { 3, 4 });
write2.moveTo(2, 0);
write2.setPixel(new double[] { Double.NaN, Double.NaN });
write3.moveTo(0, 0);
write3.setPixel(new double[] { 5, 6 });
write3.moveTo(1, 0);
write3.setPixel(new double[] { 5, 6 });
write3.moveTo(2, 0);
write3.setPixel(new double[] { 5, 6 });
/*
We expect a final coverage with values [1:2,3:4,5:6] on a single row
+---+---+---+
|1:2|3:4|5:6|
+---+---+---+
*/
final GridCoverageResource aggregate = AggregatedCoverageResource.create(null, AggregatedCoverageResource.Mode.ORDER, resource1, resource2, resource3);
((AggregatedCoverageResource) aggregate).setInterpolation(Interpolation.NEAREST);
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));
assertEquals(2, reader.getSample(1));
reader.moveTo(1, 0);
assertEquals(3, reader.getSample(0));
assertEquals(4, reader.getSample(1));
reader.moveTo(2, 0);
assertEquals(5, reader.getSample(0));
assertEquals(6, reader.getSample(1));
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class AggregatedCoverageResourceTest method forceOutputDataType.
/**
* Ensure that data-type specified by user is used instead of datasource types.
*/
@Test
public void forceOutputDataType() throws Exception {
final GridGeometry grid = new GridGeometry(new GridExtent(3, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0, 0), CommonCRS.defaultGeographic());
final GridGeometry biggerGrid = new GridGeometry(new GridExtent(4, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0, 0), CommonCRS.defaultGeographic());
final SampleDimension sd = new SampleDimension.Builder().setName("data").build();
final GridCoverage bandShort = new BufferedGridCoverage(grid, Collections.singletonList(sd), DataBuffer.TYPE_SHORT);
final GridCoverage bandInt = new BufferedGridCoverage(grid, Collections.singletonList(sd), DataBuffer.TYPE_INT);
final AggregatedCoverageResource aggregate = new AggregatedCoverageResource();
aggregate.setInterpolation(Interpolation.NEAREST);
aggregate.add(new InMemoryGridCoverageResource(bandInt));
aggregate.add(new InMemoryGridCoverageResource(bandShort));
aggregate.setDataType(DataBuffer.TYPE_DOUBLE);
RenderedImage rendering = aggregate.read(biggerGrid).render(null);
assertEquals("Infered sample type is wrong", DataBuffer.TYPE_DOUBLE, rendering.getSampleModel().getDataType());
// Test non-homogeneous aggregation
final SampleDimension userDefinedSd = new SampleDimension.Builder().setName("data").setBackground("NaN", Double.NaN).addQuantitative("percentage", 0, 1, 100d, 0d, Units.PERCENT).build();
aggregate.add(new InMemoryGridCoverageResource(new BufferedGridCoverage(grid, Collections.singletonList(userDefinedSd), DataBuffer.TYPE_DOUBLE)));
aggregate.setDataType(DataBuffer.TYPE_INT);
rendering = aggregate.read(biggerGrid).render(null);
assertEquals("Infered sample type is wrong", DataBuffer.TYPE_INT, rendering.getSampleModel().getDataType());
}
Aggregations