Search in sources :

Example 6 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class MeridianTest method testLoopN170toP170.

/**
 * Test loop around the -180 meridian.
 */
@Test
public void testLoopN170toP170() 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 7 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class MeridianTest method testEnvelopeWorld.

@Test
public void testEnvelopeWorld() throws Exception {
    final GeneralEnvelope genv = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
    genv.setRange(0, -180, +180);
    genv.setRange(1, -90, +90);
    final Geometry poly = GeometricUtilities.toJTSGeometry(genv, GeometricUtilities.WrapResolution.SPLIT);
    final MapLayers context = createFeatureLayer(poly, Geometry.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(new Dimension(360, 180), env);
    canvasDef.setBackground(Color.WHITE);
    final BufferedImage image = DefaultPortrayalService.portray(canvasDef, sceneDef);
    checkImage(image, new Rectangle(0, 0, 360, 180));
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) Geometry(org.locationtech.jts.geom.Geometry) 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)

Example 8 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class MeridianTest method createFeatureLayer.

private static <T extends Geometry> MapLayers createFeatureLayer(T geometry, Class<T> geomClass) {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName("test");
    ftb.addAttribute(geomClass).setName("geom").setCRS(CommonCRS.WGS84.normalizedGeographic()).addRole(AttributeRole.DEFAULT_GEOMETRY);
    final FeatureType type = ftb.build();
    final Feature feature = type.newInstance();
    JTS.setCRS(geometry, CommonCRS.WGS84.normalizedGeographic());
    feature.setPropertyValue("geom", geometry);
    final FeatureSet col = new InMemoryFeatureSet(type, Arrays.asList(feature));
    final PolygonSymbolizer symbol = SF.polygonSymbolizer(SF.stroke(Color.BLACK, 0), SF.fill(Color.RED), null);
    final MutableStyle style = SF.style(symbol);
    final MapLayer layer = MapBuilder.createLayer(col);
    layer.setStyle(style);
    final MapLayers context = MapBuilder.createContext();
    context.getComponents().add(layer);
    return context;
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) MutableStyle(org.geotoolkit.style.MutableStyle) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) MapLayer(org.apache.sis.portrayal.MapLayer) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) FeatureSet(org.apache.sis.storage.FeatureSet) Feature(org.opengis.feature.Feature) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 9 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class MeridianTest method testFullWrapAroundGeometry.

/**
 * Test a geometry which makes a full width wrap around.
 * Some geometry at the poles often have a line segment which makes a complete
 * world wrap.
 */
@Test
public void testFullWrapAroundGeometry() throws Exception {
    final Polygon poly = GF.createPolygon(new Coordinate[] { new Coordinate(-180, +10), new Coordinate(+180, +10), new Coordinate(+180, -10), new Coordinate(-180, -10), new Coordinate(-180, +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(new Dimension(360, 180), env);
    canvasDef.setBackground(Color.WHITE);
    final BufferedImage image = DefaultPortrayalService.portray(canvasDef, sceneDef);
    checkImage(image, new Rectangle(0, 80, 360, 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 10 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class MeridianTest method testImageCrossN190toN170.

/**
 * Test coverage that overlaps the -180 meridian.
 */
@Test
public void testImageCrossN190toN170() throws Exception {
    final GeneralEnvelope covEnv = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
    covEnv.setRange(0, -190, -170);
    covEnv.setRange(1, -10, +10);
    final MapLayers context = createCoverageLayer(covEnv);
    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);
    checkImage(image, new Rectangle(350, 80, 10, 20), new Rectangle(0, 80, 10, 20));
}
Also used : 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