use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class PortrayalServiceTest method testCoverageVisit0_360.
/**
* Test picking on a coverage in range 0-360.
* @throws PortrayalException
*/
@Test
public void testCoverageVisit0_360() throws PortrayalException {
// Create 0-360 coverage
final BufferedImage img = new BufferedImage(350, 180, BufferedImage.TYPE_INT_ARGB);
CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
crs = AbstractCRS.castOrCopy(crs).forConvention(AxesConvention.POSITIVE_RANGE);
final AffineTransform2D gridToCrs = new AffineTransform2D(1, 0, 0, -1, 0, 90);
final GridExtent extent = new GridExtent(350, 180);
final GridGeometry gg = new GridGeometry(extent, PixelInCell.CELL_CORNER, gridToCrs, crs);
final GridCoverageBuilder gcb = new GridCoverageBuilder();
gcb.setValues(img);
gcb.setDomain(gg);
final GridCoverage coverage = gcb.build();
final GridCoverageResource gcr = new InMemoryGridCoverageResource(coverage);
final MapLayer layer = MapBuilder.createCoverageLayer(gcr);
final MapLayers context = MapBuilder.createContext();
context.getComponents().add(layer);
final GeneralEnvelope viewEnv = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
viewEnv.setRange(0, -180, +180);
viewEnv.setRange(1, -90, +90);
final AtomicInteger count = new AtomicInteger();
GraphicVisitor gv = new GraphicVisitor() {
@Override
public void startVisit() {
}
@Override
public void endVisit() {
}
@Override
public void visit(Presentation graphic, RenderingContext context, SearchArea area) {
count.incrementAndGet();
}
@Override
public boolean isStopRequested() {
return false;
}
};
final SceneDef scene = new SceneDef(context);
final CanvasDef canvas = new CanvasDef(new Dimension(360, 180), viewEnv);
final VisitDef visit = new VisitDef(new Rectangle(10, 80, 2, 2), gv);
DefaultPortrayalService.visit(canvas, scene, visit);
assertEquals(1, count.get());
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class VisitorTest method intersectionCoverageTest.
/**
* Coverage visitor test
*/
@Test
@Ignore("Need to revisit DataBuffer construction.")
public void intersectionCoverageTest() throws Exception {
final float[][] data = new float[180][360];
for (int i = 0; i < 180; i++) Arrays.fill(data[i], 15f);
final GridCoverageBuilder gcb = new GridCoverageBuilder();
gcb.setValues(BufferedImages.toDataBuffer1D(data), null);
final AffineTransform trs = new AffineTransform(1, 0, 0, -1, -180, 90);
gcb.setDomain(new GridGeometry(new GridExtent(360, 180), PixelInCell.CELL_CENTER, new AffineTransform2D(trs), CommonCRS.WGS84.normalizedGeographic()));
gcb.setRanges(new SampleDimension.Builder().setName(0).build());
final MapLayer cml = MapBuilder.createLayer(new InMemoryGridCoverageResource(gcb.build()));
MapLayers context = MapBuilder.createContext(CommonCRS.WGS84.normalizedGeographic());
context.getComponents().add(cml);
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
env.setRange(0, -180, 180);
env.setRange(1, -90, 90);
final Dimension dim = new Dimension(360, 180);
// starting at top left corner
final Shape shparea = new Rectangle(195, 75, 2, 2);
final ListVisitor visitor = new ListVisitor();
DefaultPortrayalService.visit(context, env, dim, true, null, shparea, visitor);
assertTrue(visitor.coverages.size() != 0);
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class RasterSymbolizerRenderer method presentations.
@Override
public Stream<Presentation> presentations(MapLayer layer, Feature feature) {
final RasterSymbolizer sourceSymbol = symbol.getSource();
final Object candidate = GO2Utilities.evaluate(sourceSymbol.getGeometry(), feature, null, null);
GridCoverageResource ref = null;
if (candidate instanceof GridCoverageResource) {
ref = (GridCoverageResource) candidate;
} else if (candidate instanceof GridCoverage) {
ref = new InMemoryGridCoverageResource((GridCoverage) candidate);
} else {
return Stream.empty();
}
try {
final int[] channelSelection = channelSelection(sourceSymbol, ref);
final GridCoverage dataCoverage = getObjectiveCoverage(ref, renderingContext.getGridGeometry(), false, channelSelection);
if (dataCoverage == null) {
return Stream.empty();
}
final GridCoverage2D dataImage = applyStyle(ref, dataCoverage, sourceSymbol);
final RasterPresentation rasterPresentation = new RasterPresentation(layer, ref, dataImage);
rasterPresentation.forGrid(renderingContext);
return Stream.concat(Stream.of(rasterPresentation), outline(layer, dataImage.getGridGeometry()));
} catch (NoSuchDataException | DisjointExtentException e) {
LOGGER.log(Level.FINE, "Disjoint exception: " + e.getMessage(), e);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Portrayal exception: " + e.getMessage(), e);
}
return Stream.empty();
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class RasterSymbolizerRenderer method presentations.
@Override
public Stream<Presentation> presentations(MapLayer layer, Resource rs) {
if (rs instanceof BandedCoverageResource) {
BandedCoverageResource bcr = (BandedCoverageResource) rs;
try {
GridCoverage coverage = BandedCoverageResource.sample(bcr, renderingContext.getGridGeometry2D());
rs = new InMemoryGridCoverageResource(rs.getIdentifier().orElse(null), coverage);
} catch (DataStoreException ex) {
ExceptionPresentation ep = new ExceptionPresentation(ex);
ep.setLayer(layer);
ep.setResource(rs);
return Stream.of(ep);
}
}
if (rs instanceof GridCoverageResource) {
GridCoverageResource ref = (GridCoverageResource) rs;
try {
final RasterSymbolizer sourceSymbol = symbol.getSource();
final int[] channelSelection = channelSelection(sourceSymbol, ref);
final GridCoverage dataCoverage = getObjectiveCoverage(ref, renderingContext.getGridGeometry(), false, channelSelection);
if (dataCoverage == null) {
return Stream.empty();
}
final GridCoverage2D dataImage = applyStyle(ref, dataCoverage, sourceSymbol);
final RasterPresentation rasterPresentation = new RasterPresentation(layer, layer.getData(), dataImage);
rasterPresentation.forGrid(renderingContext);
return Stream.concat(Stream.of(rasterPresentation), outline(layer, dataImage.getGridGeometry()));
} catch (NoSuchDataException | DisjointExtentException e) {
LOGGER.log(Level.FINE, "Disjoint exception: " + e.getMessage(), e);
} catch (Exception e) {
ExceptionPresentation ep = new ExceptionPresentation(e);
ep.setLayer(layer);
ep.setResource(rs);
return Stream.of(ep);
}
} else {
return super.presentations(layer, rs);
}
return Stream.empty();
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class RasterSymbolizerTest method disjointCoverageIsPropertyShorted.
@Test
public void disjointCoverageIsPropertyShorted() {
final BufferedImage image = new BufferedImage(2, 2, BufferedImage.TYPE_BYTE_GRAY);
ImageUtilities.fill(image.getRaster(), 42);
final GridGeometry geom = new GridGeometry(new GridExtent(2, 2), PixelInCell.CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 10, 10), CommonCRS.defaultGeographic());
final GridCoverage baseData = new GridCoverage2D(geom, null, image);
final GridGeometry canvasGeom = new GridGeometry(new GridExtent(5, 5), new Envelope2D(CommonCRS.defaultGeographic(), -100, -20, 40, 20), GridOrientation.HOMOTHETY);
new MockRasterRenderer(canvasGeom).testObjectiveDisjoint(new InMemoryGridCoverageResource(baseData));
}
Aggregations