Search in sources :

Example 16 with MapLayers

use of org.apache.sis.portrayal.MapLayers 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 17 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class ColorModelTest method testReprojectionCoverageARGB.

@Test
public void testReprojectionCoverageARGB() throws TransformException, PortrayalException, NoSuchAuthorityCodeException, FactoryException {
    // create a test coverage
    final BufferedImage img = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g2d = img.createGraphics();
    g2d.setColor(Color.GREEN);
    g2d.fillRect(0, 0, 500, 500);
    final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
    env.setRange(0, 0, 20);
    env.setRange(1, 0, 20);
    final GridCoverage coverage = new GridCoverage2D(new GridGeometry(null, env, GridOrientation.HOMOTHETY), null, img);
    // display it
    final MapLayers context = MapBuilder.createContext();
    final MapLayer cl = MapBuilder.createCoverageLayer(coverage, SF.style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER), "coverage");
    context.getComponents().add(cl);
    final Envelope envelope = Envelopes.transform(env, CRS.forCode("EPSG:3031"));
    final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), envelope);
    cdef.setBackground(Color.WHITE);
    final BufferedImage result = DefaultPortrayalService.portray(cdef, new SceneDef(context));
    // background is opaque we should obtain an RGB color model since raster styles
    // are unpredictable
    assertTrue(!(result.getColorModel() instanceof IndexColorModel));
    assertEquals(ColorSpace.TYPE_RGB, result.getColorModel().getColorSpace().getType());
    assertEquals(3, result.getColorModel().getNumComponents());
    assertEquals(3, result.getColorModel().getNumColorComponents());
    // check we don't have any black reprojection pixels
    int[] buffer = new int[4];
    final Raster raster = result.getData();
    for (int x = 0; x < raster.getWidth(); x++) {
        for (int y = 0; y < raster.getHeight(); y++) {
            raster.getPixel(x, y, buffer);
            if (buffer[0] == 0 && buffer[1] == 0 && buffer[2] == 0) {
                // black pixel
                fail("reprojection should not have generated black pixels.");
            }
        }
    }
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) MapLayer(org.apache.sis.portrayal.MapLayer) Raster(java.awt.image.Raster) Dimension(java.awt.Dimension) Envelope(org.opengis.geometry.Envelope) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) BufferedImage(java.awt.image.BufferedImage) Point(org.locationtech.jts.geom.Point) Graphics2D(java.awt.Graphics2D) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) SceneDef(org.geotoolkit.display2d.service.SceneDef) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) MapLayers(org.apache.sis.portrayal.MapLayers) IndexColorModel(java.awt.image.IndexColorModel) Test(org.junit.Test)

Example 18 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class ColorModelTest method testSolidColorBackgroundWithAA.

@Test
public void testSolidColorBackgroundWithAA() throws NoSuchAuthorityCodeException, FactoryException, PortrayalException {
    final MapLayers context = MapBuilder.createContext();
    final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.geographic());
    env.setRange(0, -180, 180);
    env.setRange(1, -90, 90);
    final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
    cdef.setBackground(Color.GREEN);
    final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context, new Hints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)));
    // background is single color opaque we should obtain an RGB color model because of active
    // anti-aliasing
    assertTrue(!(img.getColorModel() instanceof IndexColorModel));
    assertEquals(ColorSpace.TYPE_RGB, img.getColorModel().getColorSpace().getType());
    assertEquals(3, img.getColorModel().getNumComponents());
    assertEquals(3, img.getColorModel().getNumColorComponents());
}
Also used : Hints(org.geotoolkit.factory.Hints) RenderingHints(java.awt.RenderingHints) SceneDef(org.geotoolkit.display2d.service.SceneDef) Dimension(java.awt.Dimension) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) IndexColorModel(java.awt.image.IndexColorModel) Test(org.junit.Test)

Example 19 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class ColorModelTest method testOpaqueUnpredictableBackground.

@Test
public void testOpaqueUnpredictableBackground() throws NoSuchAuthorityCodeException, FactoryException, PortrayalException {
    final MapLayers context = MapBuilder.createContext();
    final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.geographic());
    env.setRange(0, -180, 180);
    env.setRange(1, -90, 90);
    final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
    cdef.setBackground(Color.GREEN);
    final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context, null, new PortrayalExtension() {

        @Override
        public void completeCanvas(J2DCanvas canvas) throws PortrayalException {
            canvas.setBackgroundPainter(new GradiantColorPainter());
        }
    }));
    // background is opaque we should obtain an RGB color model
    assertTrue(!(img.getColorModel() instanceof IndexColorModel));
    assertEquals(ColorSpace.TYPE_RGB, img.getColorModel().getColorSpace().getType());
    assertEquals(3, img.getColorModel().getNumComponents());
    assertEquals(3, img.getColorModel().getNumColorComponents());
}
Also used : SceneDef(org.geotoolkit.display2d.service.SceneDef) PortrayalExtension(org.geotoolkit.display2d.service.PortrayalExtension) Dimension(java.awt.Dimension) GradiantColorPainter(org.geotoolkit.display2d.canvas.painter.GradiantColorPainter) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) J2DCanvas(org.geotoolkit.display2d.canvas.J2DCanvas) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) IndexColorModel(java.awt.image.IndexColorModel) Test(org.junit.Test)

Example 20 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class ColorModelTest method testSolidColorBackground.

@Test
public void testSolidColorBackground() throws NoSuchAuthorityCodeException, FactoryException, PortrayalException {
    final MapLayers context = MapBuilder.createContext();
    final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.geographic());
    env.setRange(0, -180, 180);
    env.setRange(1, -90, 90);
    final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
    cdef.setBackground(Color.GREEN);
    final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context));
    assertTrue(img.getColorModel() instanceof IndexColorModel);
    final IndexColorModel icm = (IndexColorModel) img.getColorModel();
    // we should have only two value
    assertEquals(2, icm.getMapSize());
    assertTrue(Color.GREEN.getRGB() == icm.getRGB(0) || Color.GREEN.getRGB() == icm.getRGB(1));
}
Also used : SceneDef(org.geotoolkit.display2d.service.SceneDef) Dimension(java.awt.Dimension) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) IndexColorModel(java.awt.image.IndexColorModel) Test(org.junit.Test)

Aggregations

MapLayers (org.apache.sis.portrayal.MapLayers)104 Dimension (java.awt.Dimension)61 BufferedImage (java.awt.image.BufferedImage)57 Test (org.junit.Test)57 MapLayer (org.apache.sis.portrayal.MapLayer)51 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)47 Rectangle (java.awt.Rectangle)26 CanvasDef (org.geotoolkit.display2d.service.CanvasDef)26 SceneDef (org.geotoolkit.display2d.service.SceneDef)26 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)22 Coordinate (org.locationtech.jts.geom.Coordinate)17 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)16 MutableStyle (org.geotoolkit.style.MutableStyle)16 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)16 Graphics2D (java.awt.Graphics2D)15 SampleDimension (org.apache.sis.coverage.SampleDimension)15 Feature (org.opengis.feature.Feature)14 FeatureType (org.opengis.feature.FeatureType)14 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)13 FeatureSet (org.apache.sis.storage.FeatureSet)13