Search in sources :

Example 96 with MapLayers

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

the class VisitorTest method intersectionFeatureTest.

/**
 * Feature visitor test.
 */
@Test
public void intersectionFeatureTest() throws Exception {
    final MutableStyleFactory sf = new DefaultStyleFactory();
    final GeographicCRS crs = CommonCRS.WGS84.normalizedGeographic();
    final FeatureTypeBuilder sftb = new FeatureTypeBuilder();
    sftb.setName("testingIntersect");
    sftb.addAttribute(String.class).setName("id").addRole(AttributeRole.IDENTIFIER_COMPONENT);
    sftb.addAttribute(Polygon.class).setName("geom").setCRS(crs).addRole(AttributeRole.DEFAULT_GEOMETRY);
    final FeatureType sft = sftb.build();
    final WritableFeatureSet collection = new InMemoryFeatureSet("id", sft);
    final Feature f = sft.newInstance();
    final GeometryFactory gf = org.geotoolkit.geometry.jts.JTS.getFactory();
    LinearRing ring = gf.createLinearRing(new Coordinate[] { new Coordinate(10, 10), new Coordinate(20, 10), new Coordinate(20, 20), new Coordinate(10, 20), new Coordinate(10, 10) });
    Polygon pol = gf.createPolygon(ring, new LinearRing[0]);
    pol.setUserData(crs);
    f.setPropertyValue("id", "id-0");
    f.setPropertyValue("geom", pol);
    collection.add(Arrays.asList(f).iterator());
    MapLayer layer = MapBuilder.createLayer(collection);
    layer.setStyle(sf.style(sf.polygonSymbolizer()));
    layer.setVisible(true);
    MapLayers context = MapBuilder.createContext(CommonCRS.WGS84.normalizedGeographic());
    context.getComponents().add(layer);
    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
    Shape shparea = new Rectangle(195, 75, 2, 2);
    ListVisitor visitor = new ListVisitor();
    // ensure we can paint image
    DefaultPortrayalService.portray(context, env, dim, true);
    DefaultPortrayalService.visit(context, env, dim, true, null, shparea, visitor);
    assertEquals(1, visitor.features.size());
    assertEquals("id-0", FeatureExt.getId(visitor.features.get(0)).getIdentifier());
    // starting at top left corner
    shparea = new Rectangle(30, 12, 2, 2);
    visitor = new ListVisitor();
    // ensure we can paint image
    DefaultPortrayalService.portray(context, env, dim, true);
    DefaultPortrayalService.visit(context, env, dim, true, null, shparea, visitor);
    assertTrue(visitor.features.size() == 0);
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) WritableFeatureSet(org.apache.sis.storage.WritableFeatureSet) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Shape(java.awt.Shape) MapLayer(org.apache.sis.portrayal.MapLayer) Rectangle(java.awt.Rectangle) MutableStyleFactory(org.geotoolkit.style.MutableStyleFactory) SampleDimension(org.apache.sis.coverage.SampleDimension) Dimension(java.awt.Dimension) Feature(org.opengis.feature.Feature) Coordinate(org.locationtech.jts.geom.Coordinate) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) Polygon(org.locationtech.jts.geom.Polygon) LinearRing(org.locationtech.jts.geom.LinearRing) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) DefaultStyleFactory(org.geotoolkit.style.DefaultStyleFactory) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 97 with MapLayers

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

the class ColorModelTest method testNoDataCM.

@Test
public void testNoDataCM() 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 BufferedImage img = DefaultPortrayalService.portray(new CanvasDef(new Dimension(800, 600), env), new SceneDef(context));
    assertTrue(img.getColorModel() instanceof IndexColorModel);
    final IndexColorModel icm = (IndexColorModel) img.getColorModel();
    // we should have only two value
    assertEquals(2, icm.getMapSize());
    // with one being transparent
    assertTrue(icm.getTransparentPixel() >= 0);
}
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)

Example 98 with MapLayers

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

the class ColorModelTest method testRasterData.

@Test
public void testRasterData() throws NoSuchAuthorityCodeException, FactoryException, PortrayalException {
    final MapLayers context = MapBuilder.createContext();
    context.getComponents().add(MapBuilder.createCoverageLayer(coverages.get(0), SF.style(SF.rasterSymbolizer()), "test"));
    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.WHITE);
    final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context));
    // background is opaque we should obtain an RGB color model since raster styles
    // are unpredictable
    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) 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 99 with MapLayers

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

the class ColorModelTest method testOpaqueStyleDatas.

@Test
public void testOpaqueStyleDatas() throws NoSuchAuthorityCodeException, FactoryException, PortrayalException {
    final MapLayers context = MapBuilder.createContext();
    context.getComponents().add(createLayer(Color.BLUE, Color.RED, Color.YELLOW));
    context.getComponents().add(createLayer(Color.BLUE, Color.GREEN, Color.GRAY));
    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.WHITE);
    final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context));
    assertTrue(img.getColorModel() instanceof IndexColorModel);
    final IndexColorModel icm = (IndexColorModel) img.getColorModel();
    assertEquals(Transparency.OPAQUE, icm.getTransparency());
    assertEquals(-1, icm.getTransparentPixel());
    assertFalse(icm.hasAlpha());
    // we should have only six value
    assertEquals(6, icm.getMapSize());
    final Set<Integer> colors = new HashSet<Integer>();
    colors.add(Color.WHITE.getRGB());
    colors.add(Color.BLUE.getRGB());
    colors.add(Color.RED.getRGB());
    colors.add(Color.YELLOW.getRGB());
    colors.add(Color.GREEN.getRGB());
    colors.add(Color.GRAY.getRGB());
    for (int i = 0; i < icm.getMapSize(); i++) {
        assertTrue(colors.contains(icm.getRGB(i)));
    }
}
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) Point(org.locationtech.jts.geom.Point) MapLayers(org.apache.sis.portrayal.MapLayers) IndexColorModel(java.awt.image.IndexColorModel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 100 with MapLayers

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

the class ColorModelTest method testJPEGOutput.

/**
 * Test that when asking a jpeg output, the resulting writen image has been
 * configured with a white background.
 */
@Test
public void testJPEGOutput() throws NoSuchAuthorityCodeException, FactoryException, IOException, PortrayalException {
    final MapLayers context = MapBuilder.createContext();
    final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.geographic());
    env.setRange(0, -180, 180);
    env.setRange(1, -90, 90);
    File tempFile = File.createTempFile("testjpeg", ".jpg");
    tempFile.deleteOnExit();
    final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
    DefaultPortrayalService.portray(cdef, new SceneDef(context), new OutputDef("image/jpeg", tempFile));
    // we should obtain a white background image
    final BufferedImage img = ImageIO.read(tempFile);
    for (int x = 0; x < img.getWidth(); x++) {
        for (int y = 0; y < img.getHeight(); y++) {
            // jpeg can't encode a perfect white image, CMY to RGB conversion lost I guess.
            Color c = new Color(img.getRGB(x, y));
            Assert.assertBetween("color is not white", 250, 255, c.getRed());
            Assert.assertBetween("color is not white", 250, 255, c.getGreen());
            Assert.assertBetween("color is not white", 250, 255, c.getBlue());
            Assert.assertBetween("color is not white", 250, 255, c.getAlpha());
        }
    }
}
Also used : Color(java.awt.Color) SceneDef(org.geotoolkit.display2d.service.SceneDef) Dimension(java.awt.Dimension) OutputDef(org.geotoolkit.display2d.service.OutputDef) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) File(java.io.File) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) BufferedImage(java.awt.image.BufferedImage) Point(org.locationtech.jts.geom.Point) MapLayers(org.apache.sis.portrayal.MapLayers) 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