use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class MeridianTest method createCoverageLayer.
private static MapLayers createCoverageLayer(Envelope env) {
final BufferedImage image = new BufferedImage((int) env.getSpan(0), (int) env.getSpan(1), BufferedImage.TYPE_INT_RGB);
final Graphics2D g2d = image.createGraphics();
g2d.setColor(Color.RED);
g2d.fillRect(0, 0, image.getWidth(), image.getHeight());
final GridCoverageBuilder gcb = new GridCoverageBuilder();
gcb.setDomain(new GridGeometry(null, PixelInCell.CELL_CORNER, new AffineTransform2D(1, 0, 0, -1, env.getMinimum(0), env.getMaximum(1)), env.getCoordinateReferenceSystem()));
gcb.setValues(image);
final GridCoverage coverage = gcb.build();
final RasterSymbolizer symbol = SF.rasterSymbolizer();
final MutableStyle style = SF.style(symbol);
final MapLayer layer = MapBuilder.createCoverageLayer(coverage, style, "test");
final MapLayers context = MapBuilder.createContext();
context.getComponents().add(layer);
return context;
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class MeridianTest method testDuplicateExact.
/**
* Test duplicated on left and right.
*/
@Test
public void testDuplicateExact() throws Exception {
final Polygon poly = GF.createPolygon(new Coordinate[] { new Coordinate(0, 0), new Coordinate(0, 10), new Coordinate(20, 10), new Coordinate(20, 0), new Coordinate(0, 0) });
final MapLayers context = createFeatureLayer(poly, Polygon.class);
final SceneDef sceneDef = new SceneDef(context);
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
// 1 on the left, 2 on the right
env.setRange(0, -540, +900);
env.setRange(1, -90, +90);
final CanvasDef canvasDef = new CanvasDef(new Dimension(360 * 4, 180), env);
canvasDef.setBackground(Color.WHITE);
final BufferedImage image = DefaultPortrayalService.portray(canvasDef, sceneDef);
checkImage(image, new Rectangle(180, 80, 20, 10), new Rectangle(180 + 360, 80, 20, 10), new Rectangle(180 + 720, 80, 20, 10), new Rectangle(180 + 1080, 80, 20, 10));
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class MeridianTest method testCrossP170toP190.
/**
* Test crossing the +180 meridian.
*/
@Test
public void testCrossP170toP190() throws Exception {
final Polygon poly = GF.createPolygon(new Coordinate[] { new Coordinate(+170, +10), new Coordinate(+190, +10), new Coordinate(+190, -10), new Coordinate(+170, -10), new Coordinate(+170, +10) });
final MapLayers context = createFeatureLayer(poly, Polygon.class);
final SceneDef sceneDef = new SceneDef(context);
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
env.setRange(0, -180, +180);
env.setRange(1, -90, +90);
final CanvasDef canvasDef = new CanvasDef();
canvasDef.setEnvelope(env);
canvasDef.setDimension(new Dimension(360, 180));
canvasDef.setBackground(Color.WHITE);
final BufferedImage image = DefaultPortrayalService.portray(canvasDef, sceneDef);
checkImage(image, new Rectangle(350, 80, 10, 20), new Rectangle(0, 80, 10, 20));
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class MeridianTest method testLoopP170toN170.
/**
* Test loop around the +180 meridian.
*/
@Test
public void testLoopP170toN170() throws Exception {
final Polygon poly = GF.createPolygon(new Coordinate[] { new Coordinate(+170, +10), new Coordinate(-170, +10), new Coordinate(-170, -10), new Coordinate(+170, -10), new Coordinate(+170, +10) });
final MapLayers context = createFeatureLayer(poly, Polygon.class);
final SceneDef sceneDef = new SceneDef(context);
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
env.setRange(0, -180, +180);
env.setRange(1, -90, +90);
final CanvasDef canvasDef = new CanvasDef();
canvasDef.setEnvelope(env);
canvasDef.setDimension(new Dimension(360, 180));
canvasDef.setBackground(Color.WHITE);
final BufferedImage image = DefaultPortrayalService.portray(canvasDef, sceneDef);
checkImage(image, new Rectangle(350, 80, 10, 20), new Rectangle(0, 80, 10, 20));
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class MeridianTest method testMultiPointWideSpan.
@Test
public void testMultiPointWideSpan() throws Exception {
final MultiPoint points = GF.createMultiPoint(new Coordinate[] { new Coordinate(+170, +10), new Coordinate(-170, +10), new Coordinate(-170, -10), new Coordinate(+170, -10) });
final MapLayers context = createFeatureLayer(points);
final SceneDef sceneDef = new SceneDef(context);
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
env.setRange(0, -180, +180);
env.setRange(1, -90, +90);
final CanvasDef canvasDef = new CanvasDef(new Dimension(360, 180), env);
canvasDef.setBackground(Color.WHITE);
final BufferedImage image = DefaultPortrayalService.portray(canvasDef, sceneDef);
ImageIO.write(image, "PNG", File.createTempFile("test", ".png"));
checkImage(image, new Rectangle(349, 79, 2, 2), new Rectangle(349, 99, 2, 2), new Rectangle(9, 79, 2, 2), new Rectangle(9, 99, 2, 2));
}
Aggregations