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));
}
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);
}
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));
}
Aggregations