Search in sources :

Example 1 with MapLayers

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;
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) MutableStyle(org.geotoolkit.style.MutableStyle) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) MapLayer(org.apache.sis.portrayal.MapLayer) BufferedImage(java.awt.image.BufferedImage) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) Graphics2D(java.awt.Graphics2D) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 2 with MapLayers

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));
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) Polygon(org.locationtech.jts.geom.Polygon) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 3 with MapLayers

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));
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) Polygon(org.locationtech.jts.geom.Polygon) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 4 with MapLayers

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));
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) Polygon(org.locationtech.jts.geom.Polygon) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 5 with MapLayers

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));
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) Coordinate(org.locationtech.jts.geom.Coordinate) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Aggregations

MapLayers (org.apache.sis.portrayal.MapLayers)104 Dimension (java.awt.Dimension)61 BufferedImage (java.awt.image.BufferedImage)57 Test (org.junit.Test)57 MapLayer (org.apache.sis.portrayal.MapLayer)51 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)47 Rectangle (java.awt.Rectangle)26 CanvasDef (org.geotoolkit.display2d.service.CanvasDef)26 SceneDef (org.geotoolkit.display2d.service.SceneDef)26 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)22 Coordinate (org.locationtech.jts.geom.Coordinate)17 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)16 MutableStyle (org.geotoolkit.style.MutableStyle)16 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)16 Graphics2D (java.awt.Graphics2D)15 SampleDimension (org.apache.sis.coverage.SampleDimension)15 Feature (org.opengis.feature.Feature)14 FeatureType (org.opengis.feature.FeatureType)14 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)13 FeatureSet (org.apache.sis.storage.FeatureSet)13