Search in sources :

Example 16 with LineSymbolizer

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

the class MapfileToSLDProcess method createLineSymbolizer.

private List<Symbolizer> createLineSymbolizer(final Feature style) {
    Expression expColor = (Expression) style.getPropertyValue(STYLE_COLOR.toString());
    Expression expWidth = (Expression) style.getPropertyValue(STYLE_WIDTH.toString());
    Expression expOpacity = (Expression) style.getPropertyValue(STYLE_OPACITY.toString());
    float[] dashes = (float[]) style.getPropertyValue(STYLE_PATTERN.toString());
    Literal explinecap = (Literal) style.getPropertyValue(STYLE_LINECAP.toString());
    Literal explinejoin = (Literal) style.getPropertyValue(STYLE_LINEJOIN.toString());
    Expression expOutlineColor = (Expression) style.getPropertyValue(STYLE_OUTLINECOLOR.toString());
    Expression expOutlineWidth = (Expression) style.getPropertyValue(STYLE_OUTLINEWIDTH.toString());
    if (expOpacity == null) {
        expOpacity = DEFAULT_STROKE_OPACITY;
    } else {
        // mapfile opacity is expressed in %, SE is in 0-1
        if (expOpacity instanceof Literal) {
            double d = ((Number) expOpacity.apply(null)).doubleValue();
            d /= 100d;
            expOpacity = FF.literal(d);
        } else {
            expOpacity = FF.divide(expOpacity, FF.literal(100));
        }
    }
    if (expWidth == null) {
        expWidth = DEFAULT_STROKE_WIDTH;
    }
    if (explinecap == null) {
        explinecap = STROKE_CAP_ROUND;
    }
    if (explinejoin == null) {
        explinejoin = DEFAULT_STROKE_JOIN;
    } else {
        // mapfile write 'miter' not 'mitre' like in sld/se
        if ("miter".equalsIgnoreCase(String.valueOf(explinejoin.getValue()))) {
            explinejoin = STROKE_JOIN_MITRE;
        }
    }
    final List<Symbolizer> symbolizers = new ArrayList<>();
    // this produce a line border effect
    if (expOutlineColor != null && expOutlineWidth != null) {
        final Expression width = FF.add(expWidth, FF.multiply(expOutlineWidth, FF.literal(2)));
        final Stroke stroke = SF.stroke(expOutlineColor, expOpacity, width, explinejoin, explinecap, null, LITERAL_ZERO_FLOAT);
        final LineSymbolizer outline = SF.lineSymbolizer("", (String) null, DEFAULT_DESCRIPTION, Units.POINT, stroke, LITERAL_ZERO_FLOAT);
        symbolizers.add(outline);
    }
    if (expColor != null) {
        // general informations
        final String name = "";
        final Description desc = DEFAULT_DESCRIPTION;
        // use the default geometry of the feature
        final String geometry = null;
        final Unit unit = Units.POINT;
        final Expression offset = LITERAL_ZERO_FLOAT;
        // the visual element
        final Expression dashOffset = LITERAL_ZERO_FLOAT;
        final Stroke stroke = SF.stroke(expColor, expOpacity, expWidth, explinejoin, explinecap, dashes, dashOffset);
        final LineSymbolizer symbolizer = SF.lineSymbolizer(name, geometry, desc, unit, stroke, offset);
        symbolizers.add(symbolizer);
    }
    return symbolizers;
}
Also used : Stroke(org.opengis.style.Stroke) Description(org.opengis.style.Description) ArrayList(java.util.ArrayList) Unit(javax.measure.Unit) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) Symbolizer(org.opengis.style.Symbolizer) Expression(org.opengis.filter.Expression) Literal(org.opengis.filter.Literal) LineSymbolizer(org.opengis.style.LineSymbolizer)

Example 17 with LineSymbolizer

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

the class Styles method graphicStrokeLine.

public static MutableStyle graphicStrokeLine() throws URISyntaxException {
    // general informations
    final String name = "mySymbol";
    final Description desc = DEFAULT_DESCRIPTION;
    // use the default geometry of the feature
    final String geometry = null;
    final Unit unit = Units.POINT;
    final Expression offset = LITERAL_ONE_FLOAT;
    // the stroke fill
    // a pattern that will be repeated like a mosaic
    final Expression size = FF.literal(12);
    final Expression opacity = LITERAL_ONE_FLOAT;
    final Expression rotation = LITERAL_ONE_FLOAT;
    final AnchorPoint anchor = DEFAULT_ANCHOR_POINT;
    final Displacement disp = DEFAULT_DISPLACEMENT;
    final List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
    final GraphicalSymbol external = SF.externalGraphic(SF.onlineResource(Styles.class.getResource("/data/fish.png").toURI()), "image/png", null);
    symbols.add(external);
    final Graphic graphic = SF.graphic(symbols, opacity, size, rotation, anchor, disp);
    final Expression initialGap = LITERAL_ZERO_FLOAT;
    final Expression strokeGap = FF.literal(10);
    final GraphicStroke graphicStroke = SF.graphicStroke(graphic, strokeGap, initialGap);
    // the visual element
    final Expression color = SF.literal(Color.BLUE);
    final Expression width = FF.literal(4);
    final Expression linecap = STROKE_CAP_ROUND;
    final Expression linejoin = STROKE_JOIN_BEVEL;
    final float[] dashes = new float[] { 8, 4, 2, 2, 2, 2, 2, 4 };
    final Expression dashOffset = LITERAL_ZERO_FLOAT;
    final Stroke stroke = SF.stroke(graphicStroke, color, opacity, width, linejoin, linecap, dashes, dashOffset);
    final LineSymbolizer symbolizer = SF.lineSymbolizer(name, geometry, desc, unit, stroke, offset);
    final MutableStyle style = SF.style(symbolizer);
    return style;
}
Also used : Stroke(org.opengis.style.Stroke) GraphicStroke(org.opengis.style.GraphicStroke) Description(org.opengis.style.Description) Graphic(org.opengis.style.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) GraphicStroke(org.opengis.style.GraphicStroke) ArrayList(java.util.ArrayList) Unit(javax.measure.Unit) Displacement(org.opengis.style.Displacement) AnchorPoint(org.opengis.style.AnchorPoint) MutableStyle(org.geotoolkit.style.MutableStyle) Expression(org.opengis.filter.Expression) LineSymbolizer(org.opengis.style.LineSymbolizer)

Example 18 with LineSymbolizer

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

the class Styles method defaultLine.

// ////////////////////////////////////////////////////////////////////
// LINE SYMBOLIZER //////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////
public static MutableStyle defaultLine() {
    final LineSymbolizer symbol = DEFAULT_LINE_SYMBOLIZER;
    final MutableStyle style = SF.style(symbol);
    return style;
}
Also used : MutableStyle(org.geotoolkit.style.MutableStyle) LineSymbolizer(org.opengis.style.LineSymbolizer)

Aggregations

LineSymbolizer (org.opengis.style.LineSymbolizer)18 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)9 Stroke (org.opengis.style.Stroke)8 MutableStyle (org.geotoolkit.style.MutableStyle)7 PointSymbolizer (org.opengis.style.PointSymbolizer)7 Unit (javax.measure.Unit)6 Expression (org.opengis.filter.Expression)6 Description (org.opengis.style.Description)6 TextSymbolizer (org.opengis.style.TextSymbolizer)6 ArrayList (java.util.ArrayList)5 GraphicStroke (org.opengis.style.GraphicStroke)5 GraphicalSymbol (org.opengis.style.GraphicalSymbol)4 RasterSymbolizer (org.opengis.style.RasterSymbolizer)4 ExtensionSymbolizer (org.opengis.style.ExtensionSymbolizer)3 Fill (org.opengis.style.Fill)3 Graphic (org.opengis.style.Graphic)3 Symbolizer (org.opengis.style.Symbolizer)3 Color (java.awt.Color)2 JAXBElement (javax.xml.bind.JAXBElement)2 Marshaller (javax.xml.bind.Marshaller)2