Search in sources :

Example 1 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class ProjectedGeometryTest method createProjectedGeometry.

private static ProjectedGeometry createProjectedGeometry(Geometry geometry, Dimension canvasBounds, AffineTransform objToDisp) throws NoninvertibleTransformException, TransformException, FactoryException {
    final int canvasWidth = canvasBounds.width;
    final int canvasHeight = canvasBounds.height;
    // build a maplayer
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName("test");
    ftb.addAttribute(Geometry.class).setName("geom").setCRS(CommonCRS.WGS84.normalizedGeographic());
    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 List<GraphicalSymbol> symbols = new ArrayList<>();
    symbols.add(SF.mark(StyleConstants.MARK_SQUARE, SF.fill(Color.BLACK), SF.stroke(Color.BLACK, 0)));
    final Graphic graphic = SF.graphic(symbols, StyleConstants.LITERAL_ONE_FLOAT, FF.literal(2), StyleConstants.LITERAL_ZERO_FLOAT, null, null);
    final PointSymbolizer ps = SF.pointSymbolizer(graphic, null);
    final MutableStyle style = SF.style(ps);
    final MapLayer layer = MapBuilder.createLayer(col);
    layer.setStyle(style);
    // build a rendering canvas
    final J2DCanvasBuffered canvas = new J2DCanvasBuffered(CommonCRS.WGS84.normalizedGeographic(), new Dimension(canvasWidth, canvasHeight));
    canvas.applyTransform(objToDisp);
    final RenderingContext2D context = canvas.prepareContext(new BufferedImage(canvasWidth, canvasHeight, BufferedImage.TYPE_INT_ARGB).createGraphics());
    final ProjectedGeometry pg = new ProjectedGeometry(context);
    pg.setDataGeometry(geometry, CommonCRS.WGS84.normalizedGeographic());
    Envelope env = canvas.getVisibleEnvelope();
    System.out.println(env.getMinimum(0) + " " + env.getMaximum(0));
    System.out.println(env.getMinimum(1) + " " + env.getMaximum(1));
    return pg;
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) PointSymbolizer(org.opengis.style.PointSymbolizer) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) Graphic(org.opengis.style.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) MapLayer(org.apache.sis.portrayal.MapLayer) ArrayList(java.util.ArrayList) RenderingContext2D(org.geotoolkit.display2d.canvas.RenderingContext2D) Dimension(java.awt.Dimension) Envelope(org.opengis.geometry.Envelope) Feature(org.opengis.feature.Feature) BufferedImage(java.awt.image.BufferedImage) MutableStyle(org.geotoolkit.style.MutableStyle) J2DCanvasBuffered(org.geotoolkit.display2d.canvas.J2DCanvasBuffered) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) FeatureSet(org.apache.sis.storage.FeatureSet)

Example 2 with MutableStyle

use of org.geotoolkit.style.MutableStyle 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 3 with MutableStyle

use of org.geotoolkit.style.MutableStyle 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 4 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class PortrayalServiceTest method testCoveragePropertyRendering.

/**
 * Test rendering of a coverage inside a feature property.
 */
@Test
public void testCoveragePropertyRendering() throws Exception {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName("test");
    ftb.addAttribute(GridCoverage.class).setName("coverage");
    final FeatureType ft = ftb.build();
    final BufferedImage img = new BufferedImage(90, 90, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g = img.createGraphics();
    g.setColor(Color.GREEN);
    g.fillRect(0, 0, 90, 90);
    g.dispose();
    final GridCoverageBuilder gcb = new GridCoverageBuilder();
    gcb.setDomain(new GridGeometry(null, PixelInCell.CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0.5, 0.5), CommonCRS.WGS84.normalizedGeographic()));
    gcb.setValues(img);
    final Feature f = ft.newInstance();
    f.setPropertyValue("coverage", gcb.build());
    final FeatureSet collection = new InMemoryFeatureSet(ft, Arrays.asList(f));
    final String name = "mySymbol";
    final Description desc = DEFAULT_DESCRIPTION;
    final String geometry = "coverage";
    final Unit unit = Units.POINT;
    final Expression opacity = LITERAL_ONE_FLOAT;
    final ChannelSelection channels = null;
    final OverlapBehavior overlap = null;
    final ColorMap colormap = null;
    final ContrastEnhancement enhance = null;
    final ShadedRelief relief = null;
    final Symbolizer outline = null;
    final RasterSymbolizer symbol = SF.rasterSymbolizer(name, geometry, desc, unit, opacity, channels, overlap, colormap, enhance, relief, outline);
    final MutableStyle style = SF.style(symbol);
    final MapLayer layer = MapBuilder.createLayer(collection);
    layer.setStyle(style);
    final MapLayers context = MapBuilder.createContext();
    context.getComponents().add(layer);
    final SceneDef sdef = new SceneDef(context);
    final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
    env.setRange(0, -180, +180);
    env.setRange(1, -90, +90);
    final CanvasDef cdef = new CanvasDef(new Dimension(360, 180), env);
    final BufferedImage result = DefaultPortrayalService.portray(cdef, sdef);
    final Raster raster = result.getData();
    final int[] pixel = new int[4];
    final int[] trans = new int[] { 0, 0, 0, 0 };
    final int[] green = new int[] { 0, 255, 0, 255 };
    assertNotNull(result);
    raster.getPixel(0, 0, pixel);
    assertArrayEquals(trans, pixel);
    raster.getPixel(179, 45, pixel);
    assertArrayEquals(trans, pixel);
    raster.getPixel(181, 45, pixel);
    assertArrayEquals(green, pixel);
}
Also used : FeatureType(org.opengis.feature.FeatureType) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) MapLayer(org.apache.sis.portrayal.MapLayer) Unit(javax.measure.Unit) Feature(org.opengis.feature.Feature) BufferedImage(java.awt.image.BufferedImage) MutableStyle(org.geotoolkit.style.MutableStyle) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) GridGeometry(org.apache.sis.coverage.grid.GridGeometry) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) Dimension(java.awt.Dimension) SampleDimension(org.apache.sis.coverage.SampleDimension) Graphics2D(java.awt.Graphics2D) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) Expression(org.opengis.filter.Expression) WritableFeatureSet(org.apache.sis.storage.WritableFeatureSet) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) FeatureSet(org.apache.sis.storage.FeatureSet) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 5 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class ColorModelTest method createStyle.

private static MutableStyle createStyle(final Color... colors) {
    final MutableStyle style = SF.style();
    for (Color c : colors) {
        final MutableFeatureTypeStyle fts = SF.featureTypeStyle();
        final GraphicalSymbol gs = SF.mark(MARK_CIRCLE, SF.fill(c), SF.stroke(c, 1));
        final PointSymbolizer symbol = SF.pointSymbolizer(SF.graphic(Collections.singletonList(gs), LITERAL_ONE_FLOAT, LITERAL_ONE_FLOAT, LITERAL_ZERO_FLOAT, DEFAULT_ANCHOR_POINT, DEFAULT_DISPLACEMENT), null);
        fts.rules().add(SF.rule(symbol));
        style.featureTypeStyles().add(fts);
    }
    return style;
}
Also used : PointSymbolizer(org.opengis.style.PointSymbolizer) MutableStyle(org.geotoolkit.style.MutableStyle) Color(java.awt.Color) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) GraphicalSymbol(org.opengis.style.GraphicalSymbol)

Aggregations

MutableStyle (org.geotoolkit.style.MutableStyle)55 Expression (org.opengis.filter.Expression)20 MapLayer (org.apache.sis.portrayal.MapLayer)19 Unit (javax.measure.Unit)16 MapLayers (org.apache.sis.portrayal.MapLayers)15 Description (org.opengis.style.Description)15 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 Feature (org.opengis.feature.Feature)11 FeatureType (org.opengis.feature.FeatureType)11 Fill (org.opengis.style.Fill)11 GraphicalSymbol (org.opengis.style.GraphicalSymbol)11 Stroke (org.opengis.style.Stroke)11 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)10 FeatureSet (org.apache.sis.storage.FeatureSet)10 GraphicStroke (org.opengis.style.GraphicStroke)10 PointSymbolizer (org.opengis.style.PointSymbolizer)10 BufferedImage (java.awt.image.BufferedImage)9 MutableFeatureTypeStyle (org.geotoolkit.style.MutableFeatureTypeStyle)9 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)9