Search in sources :

Example 26 with SceneDef

use of org.geotoolkit.display2d.service.SceneDef in project geotoolkit by Geomatys.

the class GeometryExpressionTest method bufferGeoTest.

/**
 * Test a geo buffer expression around geometry.
 *
 * TODO : make a real test case
 */
@Ignore
@Test
public void bufferGeoTest() throws Exception {
    final CoordinateReferenceSystem crs2154 = CRS.forCode("EPSG:2154");
    final CoordinateReferenceSystem crs3857 = CRS.forCode("EPSG:3857");
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName("test");
    ftb.addAttribute(Point.class).setName("geom").setCRS(crs2154);
    final FeatureType type = ftb.build();
    final Point point = GO2Utilities.JTS_FACTORY.createPoint(new Coordinate(0, 0));
    JTS.setCRS(point, crs2154);
    final Feature feature = type.newInstance();
    feature.setPropertyValue("geom", point);
    final Expression geomExp = FF.function("bufferGeo", new Expression[] { FF.property("geom"), FF.literal(100), FF.literal("m") });
    final Stroke stroke = SF.stroke(Color.BLACK, 10);
    final Fill fill = SF.fill(Color.RED);
    final PolygonSymbolizer symbolizer = SF.polygonSymbolizer("", geomExp, DEFAULT_DESCRIPTION, Units.METRE, stroke, fill, DEFAULT_DISPLACEMENT, LITERAL_ZERO_FLOAT);
    final MutableStyle style = SF.style(symbolizer);
    final MapLayers context = MapBuilder.createContext();
    final MapLayer fml = MapBuilder.createLayer(FeatureStoreUtilities.collection(feature));
    fml.setStyle(style);
    context.getComponents().add(fml);
    final GeneralEnvelope env = new GeneralEnvelope(crs3857);
    final Point pt = (Point) org.apache.sis.internal.feature.jts.JTS.transform(point, CRS.findOperation(crs2154, crs3857, null).getMathTransform());
    env.setRange(0, pt.getX() - 500, pt.getX() + 500);
    env.setRange(1, pt.getY() - 500, pt.getY() + 500);
    final CanvasDef canvasDef = new CanvasDef();
    canvasDef.setEnvelope(env);
    canvasDef.setDimension(new Dimension(100, 100));
    canvasDef.setBackground(Color.WHITE);
    final SceneDef sceneDef = new SceneDef(context);
    final BufferedImage image = DefaultPortrayalService.portray(canvasDef, sceneDef);
    ImageIO.write(image, "png", new File("test.png"));
    // we must obtain a red point of 20pixel width at image center
    final int red = Color.RED.getRGB();
    final int white = Color.WHITE.getRGB();
    Assert.assertEquals(white, image.getRGB(20, 9));
    Assert.assertEquals(red, image.getRGB(20, 11));
    Assert.assertEquals(red, image.getRGB(20, 20));
    Assert.assertEquals(red, image.getRGB(20, 29));
    Assert.assertEquals(white, image.getRGB(20, 31));
    Assert.assertEquals(white, image.getRGB(9, 20));
    Assert.assertEquals(red, image.getRGB(11, 20));
    Assert.assertEquals(red, image.getRGB(20, 20));
    Assert.assertEquals(red, image.getRGB(29, 20));
    Assert.assertEquals(white, image.getRGB(31, 20));
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) Stroke(org.opengis.style.Stroke) Fill(org.opengis.style.Fill) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) MapLayer(org.apache.sis.portrayal.MapLayer) Point(org.locationtech.jts.geom.Point) Dimension(java.awt.Dimension) Feature(org.opengis.feature.Feature) BufferedImage(java.awt.image.BufferedImage) Point(org.locationtech.jts.geom.Point) MutableStyle(org.geotoolkit.style.MutableStyle) Coordinate(org.locationtech.jts.geom.Coordinate) Expression(org.opengis.filter.Expression) SceneDef(org.geotoolkit.display2d.service.SceneDef) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) File(java.io.File) MapLayers(org.apache.sis.portrayal.MapLayers) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 27 with SceneDef

use of org.geotoolkit.display2d.service.SceneDef in project geotoolkit by Geomatys.

the class MokSymbolizerTest method testSymbolizer.

@Test
public void testSymbolizer() throws PortrayalException {
    final CanvasDef cdef = new CanvasDef(new Dimension(500, 500), env);
    // test normal pass
    Hints hints = new Hints();
    hints.put(GO2Hints.KEY_MULTI_THREAD, Boolean.FALSE);
    MokSymbolizerRenderer.called = 0;
    cdef.setBackground(Color.WHITE);
    DefaultPortrayalService.portray(cdef, new SceneDef(context, hints));
    assertEquals(5, MokSymbolizerRenderer.called);
    // test multithread
    hints = new Hints();
    hints.put(GO2Hints.KEY_MULTI_THREAD, Boolean.TRUE);
    MokSymbolizerRenderer.called = 0;
    DefaultPortrayalService.portray(cdef, new SceneDef(context, hints));
    assertEquals(5, MokSymbolizerRenderer.called);
}
Also used : Hints(org.geotoolkit.factory.Hints) GO2Hints(org.geotoolkit.display2d.GO2Hints) SceneDef(org.geotoolkit.display2d.service.SceneDef) Dimension(java.awt.Dimension) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) Test(org.junit.Test)

Example 28 with SceneDef

use of org.geotoolkit.display2d.service.SceneDef in project geotoolkit by Geomatys.

the class RasterSymbolizerTest method renderRGB8BitsCoverage.

/**
 * Render a coverage with :
 * - 3 sample dimensions R,G,B
 * - 1 byte per sample
 * - Component color model
 * - 1 raster, not tiled
 */
@Test
public void renderRGB8BitsCoverage() throws FactoryException, PortrayalException {
    final BufferedImage image = new BufferedImage(360, 180, BufferedImage.TYPE_INT_RGB);
    image.setRGB(0, 0, Color.RED.getRGB());
    image.setRGB(359, 0, Color.GREEN.getRGB());
    image.setRGB(0, 179, Color.BLUE.getRGB());
    final GridExtent extent = new GridExtent(360, 180);
    final AffineTransform2D gridToCrs = new AffineTransform2D(1, 0, 0, 1, 0, 0);
    final GridGeometry grid = new GridGeometry(extent, PixelInCell.CELL_CENTER, gridToCrs, CommonCRS.WGS84.normalizedGeographic());
    /*
         * We volontarely name samples 1,2,3 to avoid use of names as a hint.
         */
    final SampleDimension red = new SampleDimension.Builder().setName("1").build();
    final SampleDimension green = new SampleDimension.Builder().setName("2").build();
    final SampleDimension blue = new SampleDimension.Builder().setName("3").build();
    final GridCoverage2D coverage = new GridCoverage2D(grid, Arrays.asList(red, green, blue), image);
    final MapLayers context = MapBuilder.createContext();
    context.getComponents().add(MapBuilder.createCoverageLayer(new InMemoryGridCoverageResource(coverage)));
    final CanvasDef cdef = new CanvasDef(grid);
    final SceneDef sdef = new SceneDef(context);
    final BufferedImage result = DefaultPortrayalService.portray(cdef, sdef);
    assertEquals(Color.RED.getRGB(), result.getRGB(0, 0));
    assertEquals(Color.GREEN.getRGB(), result.getRGB(359, 0));
    assertEquals(Color.BLUE.getRGB(), result.getRGB(0, 179));
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridExtent(org.apache.sis.coverage.grid.GridExtent) GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) MapBuilder(org.geotoolkit.map.MapBuilder) SceneDef(org.geotoolkit.display2d.service.SceneDef) SampleDimension(org.apache.sis.coverage.SampleDimension) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) BufferedImage(java.awt.image.BufferedImage) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Aggregations

CanvasDef (org.geotoolkit.display2d.service.CanvasDef)28 SceneDef (org.geotoolkit.display2d.service.SceneDef)28 MapLayers (org.apache.sis.portrayal.MapLayers)26 Test (org.junit.Test)23 Dimension (java.awt.Dimension)21 BufferedImage (java.awt.image.BufferedImage)21 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)15 MapLayer (org.apache.sis.portrayal.MapLayer)11 IndexColorModel (java.awt.image.IndexColorModel)10 GridCoverage2D (org.apache.sis.coverage.grid.GridCoverage2D)7 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)7 Hints (org.geotoolkit.factory.Hints)7 Point (org.locationtech.jts.geom.Point)7 Feature (org.opengis.feature.Feature)7 FeatureType (org.opengis.feature.FeatureType)7 File (java.io.File)6 MutableStyle (org.geotoolkit.style.MutableStyle)6 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)6 RenderingHints (java.awt.RenderingHints)5 SampleDimension (org.apache.sis.coverage.SampleDimension)5