Search in sources :

Example 1 with Fill

use of org.geotools.styling.Fill in project sldeditor by robward-scisys.

the class CharacterMarkerSymbol method convert.

/**
 * Convert.
 *
 * @param element the element
 * @return the marker graphic
 */
@Override
public List<Graphic> convert(JsonElement element) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Graphic> markerList = new ArrayList<Graphic>();
    double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
    double symbolSize = getDouble(obj, CommonSymbolKeys.SIZE);
    double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
    double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
    JsonElement fontElement = obj.get(CharacterMarkerSymbolKeys.FONT);
    if (fontElement != null) {
        JsonObject fontObj = fontElement.getAsJsonObject();
        String fontName = getString(fontObj, FontSymbolKeys.FONT_NAME);
        int code = getInt(obj, CharacterMarkerSymbolKeys.CHARACTER_INDEX);
        Expression wellKnownName = ff.literal(String.format("ttf://%s#%s", fontName, code));
        // Create colour
        Expression colour = getColour(obj.get(CommonSymbolKeys.COLOUR));
        Fill fill = styleFactory.createFill(colour);
        Stroke stroke = null;
        Mark mark = styleFactory.mark(wellKnownName, fill, stroke);
        ExternalGraphic[] externalGraphics = null;
        Mark[] marks = new Mark[1];
        marks[0] = mark;
        Symbol[] symbols = null;
        Expression opacity = null;
        Expression rotation = ff.literal(angle);
        Expression size = ff.literal(symbolSize);
        Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, opacity, size, rotation);
        // Displacement (offsets)
        if ((xOffset > 0.0) && (yOffset > 0.0)) {
            Expression expressionX = ff.literal(xOffset);
            Expression expressionY = ff.literal(yOffset);
            Displacement displacement = styleFactory.createDisplacement(expressionX, expressionY);
            graphic.setDisplacement(displacement);
        }
        markerList.add(graphic);
    }
    return markerList;
}
Also used : Fill(org.geotools.styling.Fill) Stroke(org.geotools.styling.Stroke) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) Symbol(org.geotools.styling.Symbol) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Mark(org.geotools.styling.Mark) ExternalGraphic(org.geotools.styling.ExternalGraphic) Displacement(org.geotools.styling.Displacement) Expression(org.opengis.filter.expression.Expression) JsonElement(com.google.gson.JsonElement)

Example 2 with Fill

use of org.geotools.styling.Fill in project sldeditor by robward-scisys.

the class PictureFillSymbol method convertToFill.

/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.symbols.EsriFillSymbolInterface#convertToFill(java.lang.String, com.google.gson.JsonElement, int)
     */
@Override
public List<Symbolizer> convertToFill(String layerName, JsonElement element, int transparency) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Symbolizer> symbolizerList = new ArrayList<Symbolizer>();
    Fill fill = getFill(layerName, obj, transparency);
    PolygonSymbolizer polygon = styleFactory.createPolygonSymbolizer();
    polygon.setStroke(null);
    polygon.setFill(fill);
    symbolizerList.add(polygon);
    return symbolizerList;
}
Also used : Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer)

Example 3 with Fill

use of org.geotools.styling.Fill in project sldeditor by robward-scisys.

the class PictureFillSymbol method convert.

/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.symbols.EsriSymbolInterface#convert(org.geotools.styling.Rule, com.google.gson.JsonElement, java.lang.String, int)
     */
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
    if (rule == null)
        return;
    if (element == null)
        return;
    JsonObject obj = element.getAsJsonObject();
    List<Symbolizer> symbolizerList = rule.symbolizers();
    List<Stroke> strokeList = SymbolManager.getInstance().getStrokeList(obj.get(PictureFillSymbolKeys.OUTLINE));
    Stroke stroke = null;
    if (!strokeList.isEmpty()) {
        stroke = strokeList.get(0);
    }
    Fill fill = getFill(layerName, obj, transparency);
    PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer(stroke, fill, null);
    symbolizerList.add(polygonSymbolizer);
}
Also used : Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) JsonObject(com.google.gson.JsonObject) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer)

Example 4 with Fill

use of org.geotools.styling.Fill in project sldeditor by robward-scisys.

the class SimpleFillSymbol method convert.

/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.symbols.EsriSymbolInterface#convert(org.geotools.styling.Rule, com.google.gson.JsonElement, java.lang.String, int)
     */
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
    if (element == null)
        return;
    if (rule == null)
        return;
    JsonObject obj = element.getAsJsonObject();
    @SuppressWarnings("unused") int style = getInt(obj, CommonSymbolKeys.STYLE);
    List<Symbolizer> symbolizerList = rule.symbolizers();
    JsonElement jsonOutlineElement = obj.get(SimpleFillSymbolKeys.OUTLINE);
    List<Stroke> strokeList = SymbolManager.getInstance().getStrokeList(jsonOutlineElement);
    Stroke stroke = null;
    if (strokeList != null) {
        if (!strokeList.isEmpty()) {
            stroke = strokeList.get(0);
        }
    }
    Expression fillColour = getColour(obj.get(SimpleFillSymbolKeys.FILL_COLOUR));
    Fill fill = null;
    if (fillColour != null) {
        fill = styleFactory.createFill(fillColour, getTransparency(transparency));
    }
    PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer(stroke, fill, null);
    symbolizerList.add(polygonSymbolizer);
}
Also used : Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) Expression(org.opengis.filter.expression.Expression) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Symbolizer(org.geotools.styling.Symbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer)

Example 5 with Fill

use of org.geotools.styling.Fill in project sldeditor by robward-scisys.

the class SimpleFillSymbol method convertToFill.

/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.symbols.EsriFillSymbolInterface#convertToFill(java.lang.String, com.google.gson.JsonElement, int)
     */
@Override
public List<Symbolizer> convertToFill(String layerName, JsonElement element, int transparency) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Symbolizer> symbolizerList = new ArrayList<Symbolizer>();
    Expression fillColour = getColour(obj.get(SimpleFillSymbolKeys.FILL_COLOUR));
    Expression transparencyExpression = getTransparency(transparency);
    Fill fill = null;
    if (fillColour != null) {
        fill = styleFactory.createFill(fillColour, transparencyExpression);
    }
    PolygonSymbolizer polygon = styleFactory.createPolygonSymbolizer();
    polygon.setStroke(null);
    polygon.setFill(fill);
    symbolizerList.add(polygon);
    return symbolizerList;
}
Also used : Fill(org.geotools.styling.Fill) Expression(org.opengis.filter.expression.Expression) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Symbolizer(org.geotools.styling.Symbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer)

Aggregations

Fill (org.geotools.styling.Fill)39 Expression (org.opengis.filter.expression.Expression)23 Stroke (org.geotools.styling.Stroke)18 GraphicFill (org.opengis.style.GraphicFill)17 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)14 GraphicalSymbol (org.opengis.style.GraphicalSymbol)14 Graphic (org.geotools.styling.Graphic)13 ArrayList (java.util.ArrayList)11 Mark (org.geotools.styling.Mark)11 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)10 JsonObject (com.google.gson.JsonObject)9 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)8 AnchorPoint (org.geotools.styling.AnchorPoint)7 Displacement (org.geotools.styling.Displacement)7 PointSymbolizer (org.geotools.styling.PointSymbolizer)6 Test (org.junit.Test)6 ExternalGraphic (org.geotools.styling.ExternalGraphic)5 JsonElement (com.google.gson.JsonElement)4 MarkImpl (org.geotools.styling.MarkImpl)4 Symbolizer (org.geotools.styling.Symbolizer)4