Search in sources :

Example 6 with AnchorPoint

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

the class VOGeoServerTextSymbolizer2 method updateSymbol.

/**
 * Update symbol.
 *
 * @param textSymbolizer the text symbolizer
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.detail.vendor.geoserver.VendorOptionInterface#updateSymbol(org.geotools.styling.TextSymbolizer)
     */
@Override
public void updateSymbol(TextSymbolizer textSymbolizer) {
    GroupConfigInterface fillGroup = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_FILL);
    GroupConfigInterface strokeGroup = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_STROKE);
    GroupConfigInterface group = null;
    if (textSymbolizer instanceof TextSymbolizer2) {
        TextSymbolizer2 textSymbol2 = (TextSymbolizer2) textSymbolizer;
        Expression featureDescription = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_FEATURE_DESCRIPTION);
        if (!featureDescription.toString().isEmpty()) {
            textSymbol2.setFeatureDescription(featureDescription);
        }
        Expression snippet = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_SNIPPET);
        if (!snippet.toString().isEmpty()) {
            textSymbol2.setSnippet(snippet);
        }
        // Extract OtherText
        OtherText otherText = null;
        group = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT);
        if (group != null) {
            if (group.isPanelEnabled()) {
                String target = fieldConfigVisitor.getText(FieldIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT_TARGET);
                Expression text = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT_TEXT);
                if (!target.isEmpty() && !text.toString().isEmpty()) {
                    otherText = new OtherTextImpl();
                    otherText.setTarget(target);
                    otherText.setText(text);
                }
            }
        }
        textSymbol2.setOtherText(otherText);
        // Graphic
        Graphic graphic = null;
        group = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_GRAPHIC);
        if (group.isPanelEnabled()) {
            Expression symbolType = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_SYMBOL_TYPE);
            boolean hasFill = (fillGroup == null) ? false : fillGroup.isPanelEnabled();
            boolean hasStroke = (strokeGroup == null) ? false : strokeGroup.isPanelEnabled();
            Expression size = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_SIZE);
            Expression rotation = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_ANGLE);
            List<GraphicalSymbol> symbols = symbolTypeFactory.getValue(fieldConfigManager, symbolType, hasFill, hasStroke, selectedFillPanelId);
            AnchorPoint anchor = null;
            Displacement displacement = null;
            graphic = getStyleFactory().graphic(symbols, null, size, rotation, anchor, displacement);
            if (!symbols.isEmpty()) {
                boolean overallOpacity = (symbols.get(0) instanceof ExternalGraphic);
                if (overallOpacity) {
                    Expression opacity = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_OVERALL_OPACITY);
                    graphic.setOpacity(opacity);
                }
            }
        }
        textSymbol2.setGraphic(graphic);
    }
}
Also used : ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) OtherText(org.geotools.styling.OtherText) ExternalGraphic(org.geotools.styling.ExternalGraphic) Displacement(org.geotools.styling.Displacement) OtherTextImpl(org.geotools.styling.OtherTextImpl) AnchorPoint(org.geotools.styling.AnchorPoint) TextSymbolizer2(org.geotools.styling.TextSymbolizer2) Expression(org.opengis.filter.expression.Expression) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface)

Example 7 with AnchorPoint

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

the class LineFillSymbol method convertToFill.

/**
 * Convert to fill.
 *
 * @param layerName the layer name
 * @param element the element
 * @param transparency the transparency
 * @return the list
 */
/* (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 (layerName == null) {
        return null;
    }
    if (element == null) {
        return null;
    }
    List<Symbolizer> symbolizerList = new ArrayList<Symbolizer>();
    JsonObject obj = element.getAsJsonObject();
    Expression size = ff.literal(getDouble(obj, LineFillSymbolKeys.SEPARATION));
    Expression opacity = null;
    double lineAngle = normaliseAngle(getDouble(obj, CommonSymbolKeys.ANGLE));
    Expression rotation = null;
    AnchorPoint anchorPoint = null;
    Displacement displacement = null;
    Expression fillColour = getColour(obj.get(LineFillSymbolKeys.FILL_COLOUR));
    Expression fillColourOpacity = null;
    Expression join = null;
    Expression cap = null;
    float[] dashes = null;
    Expression offset = null;
    Expression width = ff.literal(1.0);
    Stroke outlineStroke = null;
    List<Stroke> strokeList = SymbolManager.getInstance().getStrokeList(obj.get(LineFillSymbolKeys.OUTLINE));
    // TODO
    if ((strokeList != null) && (strokeList.size() == 1)) {
        outlineStroke = strokeList.get(0);
        width = outlineStroke.getWidth();
    }
    Expression wellKnownName = null;
    if (isDoubleEqual(lineAngle, 0.0) || isDoubleEqual(lineAngle, 180.0)) {
        wellKnownName = ff.literal("shape://horline");
    } else if (isDoubleEqual(lineAngle, 90.0) || isDoubleEqual(lineAngle, 270.0)) {
        wellKnownName = ff.literal("shape://vertline");
    } else if (isDoubleEqual(lineAngle, 45.0) || isDoubleEqual(lineAngle, 225.0)) {
        wellKnownName = ff.literal("shape://slash");
    } else if (isDoubleEqual(lineAngle, 135.0) || isDoubleEqual(lineAngle, 315.0)) {
        wellKnownName = ff.literal("shape://backslash");
    } else {
        wellKnownName = ff.literal("shape://vertline");
        rotation = ff.literal(lineAngle);
    }
    Fill fill = null;
    Stroke markStroke = styleFactory.stroke(fillColour, fillColourOpacity, width, join, cap, dashes, offset);
    Mark mark = styleFactory.createMark(wellKnownName, markStroke, fill, size, rotation);
    List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>();
    symbolList.add(mark);
    GraphicFill graphicFill = styleFactory.graphicFill(symbolList, opacity, size, rotation, anchorPoint, displacement);
    Fill completeFill = styleFactory.fill(graphicFill, null, null);
    PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer();
    polygonSymbolizer.setFill(completeFill);
    polygonSymbolizer.setStroke(outlineStroke);
    symbolizerList.add(polygonSymbolizer);
    return symbolizerList;
}
Also used : Stroke(org.geotools.styling.Stroke) GraphicFill(org.opengis.style.GraphicFill) Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Mark(org.geotools.styling.Mark) Symbolizer(org.geotools.styling.Symbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Displacement(org.geotools.styling.Displacement) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) GraphicFill(org.opengis.style.GraphicFill)

Example 8 with AnchorPoint

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

the class PictureFillSymbol method getFill.

/**
 * Gets the fill.
 *
 * @param layerName the layer name
 * @param obj the obj
 * @param transparency the transparency
 * @return the fill
 */
@SuppressWarnings("unused")
private Fill getFill(String layerName, JsonObject obj, int transparency) {
    double angle = getInt(obj, CommonSymbolKeys.ANGLE);
    double xOffset = getInt(obj, CommonSymbolKeys.X_OFFSET);
    double yOffset = getInt(obj, CommonSymbolKeys.Y_OFFSET);
    double xScale = getInt(obj, PictureFillSymbolKeys.X_SCALE);
    double yScale = getInt(obj, PictureFillSymbolKeys.Y_SCALE);
    Graphic graphic = null;
    JsonElement pictureElement = obj.get(PictureFillSymbolKeys.PICTURE);
    if (pictureElement != null) {
        JsonObject pictureObj = pictureElement.getAsJsonObject();
        JsonElement imageElement = pictureObj.get(CommonPictureKeys.IMAGE);
        if (imageElement != null) {
            String imageString = imageElement.getAsString();
            byte[] decodedBytes = DatatypeConverter.parseBase64Binary(imageString);
            int height = getInt(pictureObj, CommonPictureKeys.HEIGHT);
            int width = getInt(pictureObj, CommonPictureKeys.WIDTH);
            String imageType = getString(pictureObj, CommonPictureKeys.TYPE);
            ByteArrayInputStream bis = new ByteArrayInputStream(decodedBytes);
            BufferedImage image = null;
            try {
                image = ImageIO.read(bis);
                bis.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            if (image != null) {
                String filename = String.format("%s.%s", layerName, imageType);
                File file = new File(filename);
                BufferedOutputStream buffOutStream = null;
                try {
                    buffOutStream = new BufferedOutputStream(new FileOutputStream(file));
                    Expression foregroundColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
                    Expression backgroundColour = getColour(obj.get(PictureFillSymbolKeys.BACKGROUND_COLOUR));
                    if ((foregroundColour != null) && (backgroundColour != null)) {
                        setForegroundColour(foregroundColour, backgroundColour, image);
                    }
                    ImageIO.write(image, imageType, buffOutStream);
                } catch (IOException e) {
                    ConsoleManager.getInstance().exception(this, e);
                } finally {
                    if (buffOutStream != null) {
                        try {
                            buffOutStream.close();
                        } catch (IOException e) {
                            ConsoleManager.getInstance().exception(this, e);
                        }
                    }
                }
                String fileExtension = ExternalFilenames.getFileExtension(filename);
                String imageFormat = ExternalFilenames.getImageFormat(fileExtension);
                ExternalGraphic externalGraphic = styleFactory.createExternalGraphic(file.toURI().toString(), imageFormat);
                List<GraphicalSymbol> symbols = getSymbolList(externalGraphic);
                Expression size = null;
                Expression opacity = null;
                Displacement displacement = styleFactory.createDisplacement(ff.literal(xOffset), ff.literal(yOffset));
                AnchorPoint anchorPoint = null;
                graphic = styleFactory.graphic(symbols, opacity, size, ff.literal(angle), anchorPoint, displacement);
            }
        }
    }
    Fill fill = styleFactory.createFill(getColour(obj.get(CommonSymbolKeys.COLOUR)), getColour(obj.get(PictureFillSymbolKeys.BACKGROUND_COLOUR)), getTransparency(transparency), graphic);
    return fill;
}
Also used : Fill(org.geotools.styling.Fill) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) ExternalGraphic(org.geotools.styling.ExternalGraphic) AnchorPoint(org.geotools.styling.AnchorPoint) BufferedImage(java.awt.image.BufferedImage) Displacement(org.geotools.styling.Displacement) AnchorPoint(org.geotools.styling.AnchorPoint) ByteArrayInputStream(java.io.ByteArrayInputStream) Expression(org.opengis.filter.expression.Expression) JsonElement(com.google.gson.JsonElement) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 9 with AnchorPoint

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

the class TextSymbol method convert.

/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.symbols.EsriTextSymbolInterface#convert(org.geotools.styling.TextSymbolizer, com.google.gson.JsonElement, int)
     */
@SuppressWarnings("unused")
@Override
public void convert(TextSymbolizer textSymbolizer, JsonElement element, int transparency) {
    if ((element != null) && (textSymbolizer != null)) {
        JsonObject obj = element.getAsJsonObject();
        double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
        int breakCharacter = getInt(obj, TextSymbolKeys.BREAK_CHARACTER);
        int textCase = getInt(obj, TextSymbolKeys.CASE);
        double characterSpacing = getDouble(obj, TextSymbolKeys.CHARACTER_SPACING);
        double characterWidth = getDouble(obj, TextSymbolKeys.CHARACTER_WIDTH);
        double size = getDouble(obj, CommonSymbolKeys.SIZE);
        size += MXDOptions.getInstance().getFontSizeFactor();
        int direction = getInt(obj, TextSymbolKeys.DIRECTION);
        double flipAngle = getDouble(obj, TextSymbolKeys.FLIP_ANGLE);
        int horizontalAlignment = getInt(obj, TextSymbolKeys.HORIZONTAL_ALIGNMENT);
        int verticalAlignment = getInt(obj, TextSymbolKeys.VERTICAL_ALIGNMENT);
        double leading = getDouble(obj, TextSymbolKeys.LEADING);
        double margin = getDouble(obj, TextSymbolKeys.MARGIN);
        double maskSize = getDouble(obj, TextSymbolKeys.MASK_SIZE);
        int maskStyle = getInt(obj, TextSymbolKeys.MASK_STYLE);
        int position = getInt(obj, TextSymbolKeys.POSITION);
        double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
        double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
        double shadowXOffset = getDouble(obj, TextSymbolKeys.SHADOW_X_OFFSET);
        double shadowYOffset = getDouble(obj, TextSymbolKeys.SHADOW_Y_OFFSET);
        double wordSpacing = getDouble(obj, TextSymbolKeys.WORD_SPACING);
        boolean CJKCharactersRotation = getBoolean(obj, TextSymbolKeys.CJK_CHARACTERS_ROTATION);
        boolean clip = getBoolean(obj, TextSymbolKeys.CLIP);
        boolean kerning = getBoolean(obj, TextSymbolKeys.KERNING);
        boolean rightToLeft = getBoolean(obj, TextSymbolKeys.RIGHT_TO_LEFT);
        boolean rotateWithTransform = getBoolean(obj, TextSymbolKeys.ROTATE_WITH_TRANSFORM);
        boolean typeSetting = getBoolean(obj, TextSymbolKeys.TYPE_SETTING);
        // 
        // Point placement
        // 
        AnchorPoint anchorPoint = styleFactory.anchorPoint(ff.literal(0), ff.literal(0));
        Displacement displacement = styleFactory.displacement(ff.literal(xOffset), ff.literal(yOffset));
        Expression rotationExpression = ff.literal(angle);
        styleFactory.pointPlacement(anchorPoint, displacement, rotationExpression);
        // 
        // Font
        // 
        JsonElement fontElement = obj.get(TextSymbolKeys.FONT);
        if (fontElement != null) {
            JsonObject fontObj = fontElement.getAsJsonObject();
            String fontName = getString(fontObj, FontSymbolKeys.FONT_NAME);
            boolean bold = getBoolean(fontObj, FontSymbolKeys.BOLD);
            boolean italic = getBoolean(fontObj, FontSymbolKeys.ITALIC);
            boolean strikeThrough = getBoolean(fontObj, FontSymbolKeys.STRIKE_THROUGH);
            boolean underline = getBoolean(fontObj, FontSymbolKeys.UNDERLINE);
            int weight = getInt(fontObj, FontSymbolKeys.FONT_WEIGHT);
            int charset = getInt(fontObj, FontSymbolKeys.CHARSET);
            int fontSize = getInt(obj, FontSymbolKeys.FONT_SIZE);
            Expression fontFamilyExpression = ff.literal(fontName);
            Expression fontSizeExpression = ff.literal(size);
            String fontStyle = "normal";
            if (italic) {
                fontStyle = "italic";
            }
            Expression fontStyleExpression = ff.literal(fontStyle);
            String fontWeight = "normal";
            if (bold) {
                fontWeight = "bold";
            }
            Expression fontWeightExpression = ff.literal(fontWeight);
            Font font = styleFactory.createFont(fontFamilyExpression, fontStyleExpression, fontWeightExpression, fontSizeExpression);
            textSymbolizer.setFont(font);
        }
        GraphicFill graphicFill = null;
        Expression textColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
        Expression opacity = null;
        if (transparency != 0) {
            opacity = ff.literal(transparency / 255);
        }
        Fill fill = styleFactory.fill(graphicFill, textColour, opacity);
        textSymbolizer.setFill(fill);
        String geometryPropertyName = null;
        textSymbolizer.setGeometryPropertyName(geometryPropertyName);
        Expression shadowColour = getColour(obj.get(TextSymbolKeys.SHADOW_COLOUR));
    }
}
Also used : GraphicFill(org.opengis.style.GraphicFill) Fill(org.geotools.styling.Fill) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) JsonElement(com.google.gson.JsonElement) GraphicFill(org.opengis.style.GraphicFill) JsonObject(com.google.gson.JsonObject) AnchorPoint(org.geotools.styling.AnchorPoint) Displacement(org.geotools.styling.Displacement) Font(org.geotools.styling.Font)

Example 10 with AnchorPoint

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

the class DefaultSymbols method createDefaultTextSymbolizer.

/**
 * Creates the default text symbolizer.
 *
 * @return the text symbolizer
 */
public static TextSymbolizer createDefaultTextSymbolizer() {
    Expression fontFamily = ff.literal("Serif");
    Expression fontSize = ff.literal(10.0);
    Expression fontStyle = ff.literal("normal");
    Expression fontWeight = ff.literal("normal");
    Expression rotation = ff.literal(0.0);
    Expression label = ff.literal("Test");
    String geometryFieldName = null;
    Expression geometryField = ff.property(geometryFieldName);
    String name = Localisation.getString(SLDTreeTools.class, "TreeItem.newText");
    AnchorPoint anchor = null;
    Displacement displacement = null;
    PointPlacement pointPlacement = (PointPlacement) styleFactory.pointPlacement(anchor, displacement, rotation);
    Expression fillColour = ff.literal(DEFAULT_COLOUR);
    Expression fillColourOpacity = ff.literal(1.0);
    Fill fill = styleFactory.fill(null, fillColour, fillColourOpacity);
    Halo halo = null;
    List<Expression> fontFamilyList = new ArrayList<Expression>();
    fontFamilyList.add(fontFamily);
    Font font = (Font) styleFactory.font(fontFamilyList, fontStyle, fontWeight, fontSize);
    Description description = null;
    Unit<Length> unit = null;
    TextSymbolizer newTextSymbolizer = (TextSymbolizer) styleFactory.textSymbolizer(name, geometryField, description, unit, label, font, pointPlacement, halo, fill);
    return newTextSymbolizer;
}
Also used : PointPlacement(org.geotools.styling.PointPlacement) Fill(org.geotools.styling.Fill) Description(org.geotools.styling.Description) ArrayList(java.util.ArrayList) Displacement(org.opengis.style.Displacement) Font(org.geotools.styling.Font) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) Length(javax.measure.quantity.Length) TextSymbolizer(org.geotools.styling.TextSymbolizer) Halo(org.geotools.styling.Halo)

Aggregations

AnchorPoint (org.geotools.styling.AnchorPoint)16 Expression (org.opengis.filter.expression.Expression)15 Displacement (org.geotools.styling.Displacement)12 GraphicalSymbol (org.opengis.style.GraphicalSymbol)11 Graphic (org.geotools.styling.Graphic)8 Fill (org.geotools.styling.Fill)7 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)6 ArrayList (java.util.ArrayList)4 Font (org.geotools.styling.Font)4 PointSymbolizer (org.geotools.styling.PointSymbolizer)4 Stroke (org.geotools.styling.Stroke)4 GraphicFill (org.opengis.style.GraphicFill)4 JsonObject (com.google.gson.JsonObject)3 Halo (org.geotools.styling.Halo)3 MarkImpl (org.geotools.styling.MarkImpl)3 TextSymbolizer (org.geotools.styling.TextSymbolizer)3 JsonElement (com.google.gson.JsonElement)2 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)2 MultiOptionGroup (com.sldeditor.ui.detail.config.base.MultiOptionGroup)2 ConstantExpression (org.geotools.filter.ConstantExpression)2