use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class ColorModelTest method testAlphaColorBackground.
@Test
public void testAlphaColorBackground() 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(new Color(0.5f, 0.1f, 0.7f, 0.6f));
final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context));
// background is not opaque we should obtain an RGBA color model
assertTrue(!(img.getColorModel() instanceof IndexColorModel));
assertEquals(ColorSpace.TYPE_RGB, img.getColorModel().getColorSpace().getType());
assertEquals(4, img.getColorModel().getNumComponents());
assertEquals(3, img.getColorModel().getNumColorComponents());
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class ColorModelTest method testReprojectionCoverageRGB.
@Test
public void testReprojectionCoverageRGB() throws TransformException, PortrayalException, NoSuchAuthorityCodeException, FactoryException {
// create a test coverage
final BufferedImage img = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB);
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.");
}
}
}
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class CoverageImageTest method testImageLayer.
/**
* Compute and compare result image from {@link MapContext} build with {@link CoverageMapLayer},
* and sourceImage.
*
* @param sourceImage expected image will be tested.
* @param cml {@link CoverageMapLayer} use to build {@link MapContext}.
* @throws PortrayalException
*/
private void testImageLayer(RenderedImage sourceImage, MapLayer cml) throws PortrayalException {
// create a mapcontext
final MapLayers context = MapBuilder.createContext();
context.getComponents().add(cml);
outputImgDim.setSize(proportionalityCoefficient * srcWidth, proportionalityCoefficient * srcHeight);
hints = new Hints(GO2Hints.KEY_COLOR_MODEL, sourceImage.getColorModel(), RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
cdef.setDimension(outputImgDim);
sdef.setContext(context);
sdef.setHints(hints);
cdef.setEnvelope(resEnv);
final BufferedImage imgResult = DefaultPortrayalService.portray(cdef, sdef);
checkImage(sourceImage, imgResult, proportionalityCoefficient);
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class GeometryExpressionTest method bufferTest.
/**
* Test a buffer expression around geometry.
*/
@Test
public void bufferTest() throws PortrayalException, IOException {
final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.setName("test");
ftb.addAttribute(Point.class).setName("geom").setCRS(crs).addRole(AttributeRole.DEFAULT_GEOMETRY);
final FeatureType type = ftb.build();
final Point point = GO2Utilities.JTS_FACTORY.createPoint(new Coordinate(0, 0));
JTS.setCRS(point, crs);
final Feature feature = type.newInstance();
feature.setPropertyValue("geom", point);
final Expression geomExp = FF.function("buffer", FF.property("geom"), FF.literal(10));
final Fill fill = SF.fill(Color.RED);
final PolygonSymbolizer symbolizer = SF.polygonSymbolizer("", geomExp, DEFAULT_DESCRIPTION, DEFAULT_UOM, null, 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(crs);
env.setRange(0, -20, +20);
env.setRange(1, -20, +20);
final CanvasDef canvasDef = new CanvasDef();
canvasDef.setEnvelope(env);
canvasDef.setDimension(new Dimension(40, 40));
canvasDef.setBackground(Color.WHITE);
final SceneDef sceneDef = new SceneDef(context);
final BufferedImage image = DefaultPortrayalService.portray(canvasDef, sceneDef);
// we must obtain a red point of 10pixel 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.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class RasterSymbolizerTest method UTM32632Test.
/**
* Check proper image reprojection in UTM
*/
@Ignore
@Test
public void UTM32632Test() throws Exception {
final BufferedImage img = new BufferedImage(120, 90, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = img.createGraphics();
g2d.setColor(Color.GREEN);
g2d.fillRect(0, 0, 120, 90);
// set it's envelope
final GeneralEnvelope gridEnv = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
gridEnv.setRange(0, 0, 120);
gridEnv.setRange(1, 0, 90);
// create the coverage
final GridCoverage coverage = new GridCoverage2D(new GridGeometry(null, gridEnv, GridOrientation.HOMOTHETY), null, img);
final MapLayers context = MapBuilder.createContext();
final MapLayer cl = MapBuilder.createCoverageLayer(coverage, SF.style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER), "coverage");
context.getComponents().add(cl);
final GeneralEnvelope env = new GeneralEnvelope(CRS.forCode("EPSG:32632"));
env.setRange(0, -2574823.6832217844, 5487970.783439655);
env.setRange(1, 4289777.45228916, 1.0491927042028729E7);
final Hints hints = new Hints();
final SceneDef scenedef = new SceneDef(context, hints);
final CanvasDef canvasdef = new CanvasDef(new Dimension(800, 800), env);
canvasdef.setBackground(Color.WHITE);
final BufferedImage buffer = DefaultPortrayalService.portray(canvasdef, scenedef);
ImageIO.write(buffer, "PNG", new File("test.png"));
// We should obtain a green triangle crossing the image looking like this :
//
// |\
// |_\
// we can't test the shape so we test we found more and more green pixels on each line
// we expect to have a blue label at the center of the image
final int[] pixel = new int[4];
final int[] green = new int[] { 0, 255, 0, 255 };
int nbGreen = 0;
final Raster raster = buffer.getData();
for (int y = 0; y < 800; y++) {
int nb = 0;
for (int x = 0; x < 800; x++) {
raster.getPixel(x, y, pixel);
if (Arrays.equals(green, pixel)) {
nb++;
}
}
assertTrue("expected at least one green pixel", nb > 0);
assertTrue(nb >= nbGreen);
nbGreen = nb;
}
}
Aggregations