Search in sources :

Example 1 with PointSymbolizer

use of org.opengis.style.PointSymbolizer in project geotoolkit by Geomatys.

the class KmzContextInterpreter method writeSymbolizer.

/**
 * Writes KML color styles mapping SLD Symbolizers.
 * Color styles are written into KML Style selector.
 */
private AbstractStyleSelector writeSymbolizer(Symbolizer symbolizer, Style styleSelector) {
    if (symbolizer instanceof ExtensionSymbolizer) {
    } else // LineSymbolizer mapping
    if (symbolizer instanceof LineSymbolizer) {
        final LineSymbolizer lineSymbolizer = (LineSymbolizer) symbolizer;
        final LineStyle lineStyle = ((styleSelector.getLineStyle() == null) ? KML_FACTORY.createLineStyle() : styleSelector.getLineStyle());
        lineStyle.setWidth((Double) this.writeExpression(lineSymbolizer.getStroke().getWidth(), Double.class, null));
        lineStyle.setColor((Color) this.writeExpression(lineSymbolizer.getStroke().getColor(), Color.class, null));
        styleSelector.setLineStyle(lineStyle);
    } else // PointSymbolizezr mapping
    if (symbolizer instanceof PointSymbolizer) {
    // PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
    // IconStyle iconStyle = KML_FACTORY.createIconStyle();
    // GraphicalSymbol gs = ((GraphicalSymbol) pointSymbolizer.getGraphic().graphicalSymbols().get(0));
    // gs.
    } else // PolygonSymbolizer mapping
    if (symbolizer instanceof PolygonSymbolizer) {
        final PolygonSymbolizer polygonSymbolizer = (PolygonSymbolizer) symbolizer;
        final PolyStyle polyStyle = KML_FACTORY.createPolyStyle();
        // Fill
        if (polygonSymbolizer.getFill() == null) {
            polyStyle.setFill(false);
        } else {
            polyStyle.setFill(true);
            polyStyle.setColor((Color) this.writeExpression(polygonSymbolizer.getFill().getColor(), Color.class, null));
        }
        // Outline
        if (polygonSymbolizer.getStroke() == null) {
            polyStyle.setOutline(false);
        } else if (styleSelector.getLineStyle() == null) {
            polyStyle.setOutline(true);
            final LineStyle lineStyle = KML_FACTORY.createLineStyle();
            lineStyle.setColor((Color) this.writeExpression(polygonSymbolizer.getStroke().getColor(), Color.class, null));
            lineStyle.setWidth((Double) this.writeExpression(polygonSymbolizer.getStroke().getWidth(), Double.class, null));
            styleSelector.setLineStyle(lineStyle);
        }
        styleSelector.setPolyStyle(polyStyle);
    } else if (symbolizer instanceof RasterSymbolizer) {
    } else if (symbolizer instanceof TextSymbolizer) {
        final TextSymbolizer textSymbolizer = (TextSymbolizer) symbolizer;
        final LabelStyle labelStyle = KML_FACTORY.createLabelStyle();
        if (textSymbolizer.getFont() != null) {
            textSymbolizer.getFont().getSize();
        }
        if (textSymbolizer.getFill() != null) {
            labelStyle.setColor((Color) this.writeExpression(textSymbolizer.getFill().getColor(), Color.class, null));
        }
        styleSelector.setLabelStyle(labelStyle);
    }
    return styleSelector;
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) LineStyle(org.geotoolkit.data.kml.model.LineStyle) LineSymbolizer(org.opengis.style.LineSymbolizer) Color(java.awt.Color) LabelStyle(org.geotoolkit.data.kml.model.LabelStyle) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) PolyStyle(org.geotoolkit.data.kml.model.PolyStyle)

Example 2 with PointSymbolizer

use of org.opengis.style.PointSymbolizer 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 3 with PointSymbolizer

use of org.opengis.style.PointSymbolizer in project geotoolkit by Geomatys.

the class CachedPointSymbolizerTest method testMargin.

@Test
public void testMargin() throws FactoryException {
    final GridGeometry grid = new GridGeometry(new GridExtent(1, 1), CRS.getDomainOfValidity(CommonCRS.WGS84.normalizedGeographic()), GridOrientation.HOMOTHETY);
    final RenderingContext2D ctx = new RenderingContext2D(grid, null);
    {
        // NO ANCHOR, NO DISPLACEMENT
        final List<GraphicalSymbol> symbols = new ArrayList<>();
        final Stroke stroke = SF.stroke(Color.BLACK, 2);
        final Fill fill = SF.fill(Color.RED);
        final Mark mark = SF.mark(MARK_CIRCLE, fill, stroke);
        symbols.add(mark);
        final Graphic graphic = SF.graphic(symbols, LITERAL_ONE_FLOAT, FF.literal(12), LITERAL_ONE_FLOAT, DEFAULT_ANCHOR_POINT, DEFAULT_DISPLACEMENT);
        final PointSymbolizer symbolizer = SF.pointSymbolizer("mySymbol", (String) null, DEFAULT_DESCRIPTION, Units.POINT, graphic);
        final CachedSymbolizer cached = GO2Utilities.getCached(symbolizer, null);
        final float margin = cached.getMargin(null, ctx);
        // 12/2 + 2*2(stroke width)
        assertEquals(8f, margin, DELTA);
    }
    {
        // NO ANCHOR
        final List<GraphicalSymbol> symbols = new ArrayList<>();
        final Stroke stroke = SF.stroke(Color.BLACK, 2);
        final Fill fill = SF.fill(Color.RED);
        final Mark mark = SF.mark(MARK_CIRCLE, fill, stroke);
        symbols.add(mark);
        final Graphic graphic = SF.graphic(symbols, LITERAL_ONE_FLOAT, FF.literal(12), LITERAL_ONE_FLOAT, DEFAULT_ANCHOR_POINT, SF.displacement(10, 15));
        final PointSymbolizer symbolizer = SF.pointSymbolizer("mySymbol", (String) null, DEFAULT_DESCRIPTION, Units.POINT, graphic);
        final CachedSymbolizer cached = GO2Utilities.getCached(symbolizer, null);
        final float margin = cached.getMargin(null, ctx);
        // 12/2 + 2*2(stroke width) + 15(disp)
        assertEquals(23f, margin, DELTA);
    }
    {
        final List<GraphicalSymbol> symbols = new ArrayList<>();
        final Stroke stroke = SF.stroke(Color.BLACK, 2);
        final Fill fill = SF.fill(Color.RED);
        final Mark mark = SF.mark(MARK_CIRCLE, fill, stroke);
        symbols.add(mark);
        final Graphic graphic = SF.graphic(symbols, LITERAL_ONE_FLOAT, FF.literal(12), LITERAL_ONE_FLOAT, SF.anchorPoint(0, 1.7), SF.displacement(10, 15));
        final PointSymbolizer symbolizer = SF.pointSymbolizer("mySymbol", (String) null, DEFAULT_DESCRIPTION, Units.POINT, graphic);
        final CachedSymbolizer cached = GO2Utilities.getCached(symbolizer, null);
        final float margin = cached.getMargin(null, ctx);
        // 12/2 + 2*2(stroke width) + 15(disp) + 16*(1.7-0.5)
        assertEquals(23f + 19.2f, margin, DELTA);
    }
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) PointSymbolizer(org.opengis.style.PointSymbolizer) GridExtent(org.apache.sis.coverage.grid.GridExtent) Stroke(org.opengis.style.Stroke) Fill(org.opengis.style.Fill) Graphic(org.opengis.style.Graphic) RenderingContext2D(org.geotoolkit.display2d.canvas.RenderingContext2D) Mark(org.opengis.style.Mark) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 4 with PointSymbolizer

use of org.opengis.style.PointSymbolizer in project geotoolkit by Geomatys.

the class IntervalStyleBuilder method derivateSymbolizer.

/**
 * Derivate a symbolizer with a new color.
 */
private Symbolizer derivateSymbolizer(final Symbolizer symbol, final Color color) {
    if (symbol instanceof PolygonSymbolizer) {
        PolygonSymbolizer ps = (PolygonSymbolizer) symbol;
        Fill fill = sf.fill(sf.literal(color), ps.getFill().getOpacity());
        return sf.polygonSymbolizer(ps.getName(), ps.getGeometryPropertyName(), ps.getDescription(), ps.getUnitOfMeasure(), ps.getStroke(), fill, ps.getDisplacement(), ps.getPerpendicularOffset());
    } else if (symbol instanceof LineSymbolizer) {
        LineSymbolizer ls = (LineSymbolizer) symbol;
        Stroke oldStroke = ls.getStroke();
        Stroke stroke = sf.stroke(sf.literal(color), oldStroke.getOpacity(), oldStroke.getWidth(), oldStroke.getLineJoin(), oldStroke.getLineCap(), oldStroke.getDashArray(), oldStroke.getDashOffset());
        return sf.lineSymbolizer(ls.getName(), ls.getGeometryPropertyName(), ls.getDescription(), ls.getUnitOfMeasure(), stroke, ls.getPerpendicularOffset());
    } else if (symbol instanceof PointSymbolizer) {
        PointSymbolizer ps = (PointSymbolizer) symbol;
        Graphic oldGraphic = ps.getGraphic();
        Mark oldMark = (Mark) oldGraphic.graphicalSymbols().get(0);
        Fill fill = sf.fill(sf.literal(color), oldMark.getFill().getOpacity());
        List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
        symbols.add(sf.mark(oldMark.getWellKnownName(), fill, oldMark.getStroke()));
        Graphic graphic = sf.graphic(symbols, oldGraphic.getOpacity(), oldGraphic.getSize(), oldGraphic.getRotation(), oldGraphic.getAnchorPoint(), oldGraphic.getDisplacement());
        return sf.pointSymbolizer(graphic, ps.getGeometryPropertyName());
    } else {
        throw new IllegalArgumentException("unexpected symbolizer type : " + symbol);
    }
}
Also used : PointSymbolizer(org.opengis.style.PointSymbolizer) Fill(org.opengis.style.Fill) Stroke(org.opengis.style.Stroke) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) Graphic(org.opengis.style.Graphic) LineSymbolizer(org.opengis.style.LineSymbolizer) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) Mark(org.opengis.style.Mark)

Example 5 with PointSymbolizer

use of org.opengis.style.PointSymbolizer 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

PointSymbolizer (org.opengis.style.PointSymbolizer)21 Graphic (org.opengis.style.Graphic)12 GraphicalSymbol (org.opengis.style.GraphicalSymbol)12 ArrayList (java.util.ArrayList)11 Mark (org.opengis.style.Mark)10 MutableStyle (org.geotoolkit.style.MutableStyle)9 Fill (org.opengis.style.Fill)7 LineSymbolizer (org.opengis.style.LineSymbolizer)7 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)7 Stroke (org.opengis.style.Stroke)7 Test (org.junit.Test)6 Expression (org.opengis.filter.Expression)6 Unit (javax.measure.Unit)5 AnchorPoint (org.opengis.style.AnchorPoint)5 Description (org.opengis.style.Description)5 Displacement (org.opengis.style.Displacement)5 TextSymbolizer (org.opengis.style.TextSymbolizer)5 RasterSymbolizer (org.opengis.style.RasterSymbolizer)4 Color (java.awt.Color)3 BufferedImage (java.awt.image.BufferedImage)3