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