Search in sources :

Example 1 with InMemoryGridCoverageResource

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());
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) RenderingContext(org.geotoolkit.display.canvas.RenderingContext) GridExtent(org.apache.sis.coverage.grid.GridExtent) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) SearchArea(org.geotoolkit.display.SearchArea) GraphicVisitor(org.geotoolkit.display2d.GraphicVisitor) MapLayer(org.apache.sis.portrayal.MapLayer) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) SampleDimension(org.apache.sis.coverage.SampleDimension) Presentation(org.apache.sis.internal.map.Presentation) BufferedImage(java.awt.image.BufferedImage) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 2 with InMemoryGridCoverageResource

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);
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridExtent(org.apache.sis.coverage.grid.GridExtent) Shape(java.awt.Shape) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) MapLayer(org.apache.sis.portrayal.MapLayer) Rectangle(java.awt.Rectangle) SampleDimension(org.apache.sis.coverage.SampleDimension) Dimension(java.awt.Dimension) SampleDimension(org.apache.sis.coverage.SampleDimension) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) AffineTransform(java.awt.geom.AffineTransform) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) MapLayers(org.apache.sis.portrayal.MapLayers) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with InMemoryGridCoverageResource

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();
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) CachedRasterSymbolizer(org.geotoolkit.display2d.style.CachedRasterSymbolizer) DisjointExtentException(org.apache.sis.coverage.grid.DisjointExtentException) GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) RasterPresentation(org.geotoolkit.display2d.presentation.RasterPresentation) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) PortrayalException(org.geotoolkit.display.PortrayalException) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) FactoryException(org.opengis.util.FactoryException) CannotEvaluateException(org.opengis.coverage.CannotEvaluateException) IOException(java.io.IOException) DisjointExtentException(org.apache.sis.coverage.grid.DisjointExtentException) TransformException(org.opengis.referencing.operation.TransformException) ProcessException(org.geotoolkit.process.ProcessException) DataStoreException(org.apache.sis.storage.DataStoreException)

Example 4 with InMemoryGridCoverageResource

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();
}
Also used : DisjointExtentException(org.apache.sis.coverage.grid.DisjointExtentException) DataStoreException(org.apache.sis.storage.DataStoreException) GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) BandedCoverageResource(org.geotoolkit.storage.coverage.BandedCoverageResource) RasterPresentation(org.geotoolkit.display2d.presentation.RasterPresentation) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) PortrayalException(org.geotoolkit.display.PortrayalException) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) FactoryException(org.opengis.util.FactoryException) CannotEvaluateException(org.opengis.coverage.CannotEvaluateException) IOException(java.io.IOException) DisjointExtentException(org.apache.sis.coverage.grid.DisjointExtentException) TransformException(org.opengis.referencing.operation.TransformException) ProcessException(org.geotoolkit.process.ProcessException) DataStoreException(org.apache.sis.storage.DataStoreException) RasterSymbolizer(org.opengis.style.RasterSymbolizer) CachedRasterSymbolizer(org.geotoolkit.display2d.style.CachedRasterSymbolizer) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) ExceptionPresentation(org.apache.sis.internal.map.ExceptionPresentation) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource)

Example 5 with InMemoryGridCoverageResource

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));
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridExtent(org.apache.sis.coverage.grid.GridExtent) GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) Envelope2D(org.apache.sis.geometry.Envelope2D) BufferedImage(java.awt.image.BufferedImage) 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