Search in sources :

Example 21 with Graphic

use of org.geotools.styling.Graphic 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 22 with Graphic

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

the class SimpleMarkerSymbol 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;
    List<Symbolizer> symbolizerList = rule.symbolizers();
    List<Graphic> markerList = convert(element);
    if (markerList != null) {
        for (Graphic marker : markerList) {
            PointSymbolizer pointSymbolizer = styleFactory.createPointSymbolizer(marker, null);
            symbolizerList.add(pointSymbolizer);
        }
    }
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer)

Example 23 with Graphic

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

the class DefaultSymbols method createDefaultPointSymbolizer.

/**
 * Creates the default point symbolizer.
 *
 * @return the point symbolizer
 */
public static PointSymbolizer createDefaultPointSymbolizer() {
    String geometryFieldName = null;
    Expression geometryField = ff.property(geometryFieldName);
    List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>();
    Stroke stroke = null;
    AnchorPoint anchorPoint = null;
    Displacement displacement = null;
    Fill fill = styleFactory.createFill(ff.literal(DEFAULT_MARKER_COLOUR));
    GraphicalSymbol symbol = styleFactory.mark(ff.literal(DEFAULT_MARKER_SYMBOL), fill, stroke);
    symbolList.add(symbol);
    Graphic graphic = styleFactory.graphic(symbolList, ff.literal(DEFAULT_COLOUR_OPACITY), ff.literal(DEFAULT_MARKER_SYMBOL_SIZE), ff.literal(0.0), anchorPoint, displacement);
    PointSymbolizer newPointSymbolizer = (PointSymbolizer) styleFactory.pointSymbolizer(Localisation.getString(SLDTreeTools.class, "TreeItem.newMarker"), geometryField, null, null, graphic);
    return newPointSymbolizer;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) Displacement(org.opengis.style.Displacement)

Example 24 with Graphic

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

the class StrokeDetails method populateStroke.

/**
 * Populate stroke.
 *
 * @param symbolizerType the symbolizer type
 * @param stroke the stroke
 */
private void populateStroke(Class<?> symbolizerType, Stroke stroke) {
    Expression expColour = null;
    Expression expStrokeColour = null;
    Expression expOpacity = null;
    Expression expStrokeWidth = null;
    Expression expStrokeOffset = null;
    Expression expStrokeLineCap = null;
    Expression expStrokeLineJoin = null;
    Expression expStrokeDashArray = null;
    Expression expAnchorPointX = null;
    Expression expAnchorPointY = null;
    Expression expDisplacementX = null;
    Expression expDisplacementY = null;
    Expression expGap = null;
    Expression expInitialGap = null;
    Expression expSymbolSize = null;
    Expression expSymbolRotation = null;
    if (stroke == null) {
        expColour = getFilterFactory().literal("#000000");
        expOpacity = getFilterFactory().literal(1.0);
        symbolTypeFactory.setSolidFill(fieldConfigManager, expColour, expOpacity);
        expStrokeWidth = getFilterFactory().literal(1.0);
        expStrokeOffset = getFilterFactory().literal(0.0);
        expStrokeLineCap = getFilterFactory().literal("round");
        expStrokeLineJoin = getFilterFactory().literal("round");
        expStrokeDashArray = getFilterFactory().literal("");
    } else {
        Graphic graphicFill = stroke.getGraphicFill();
        Graphic graphicStroke = stroke.getGraphicStroke();
        if ((graphicFill == null) && (graphicStroke == null)) {
            expOpacity = stroke.getOpacity();
            symbolTypeFactory.setSolidFill(fieldConfigManager, stroke.getColor(), stroke.getOpacity());
        }
        expOpacity = stroke.getOpacity();
        expStrokeWidth = stroke.getWidth();
        expStrokeOffset = stroke.getDashOffset();
        expStrokeLineCap = stroke.getLineCap();
        expStrokeLineJoin = stroke.getLineJoin();
        expColour = stroke.getColor();
        List<Float> dashesArray = getStrokeDashArray(stroke);
        expStrokeDashArray = getFilterFactory().literal(createDashArrayString(dashesArray));
        if (graphicStroke != null) {
            // Anchor points
            AnchorPoint anchorPoint = graphicStroke.getAnchorPoint();
            if (anchorPoint != null) {
                expAnchorPointX = anchorPoint.getAnchorPointX();
                expAnchorPointY = anchorPoint.getAnchorPointY();
            } else {
                expAnchorPointX = defaultAnchorPoint.getAnchorPointX();
                expAnchorPointY = defaultAnchorPoint.getAnchorPointY();
            }
            // Displacement
            Displacement displacement = graphicStroke.getDisplacement();
            if (displacement != null) {
                expDisplacementX = displacement.getDisplacementX();
                expDisplacementY = displacement.getDisplacementY();
            } else {
                expDisplacementX = defaultDisplacement.getDisplacementX();
                expDisplacementY = defaultDisplacement.getDisplacementY();
            }
            expGap = graphicStroke.getGap();
            expInitialGap = graphicStroke.getInitialGap();
            expSymbolSize = graphicStroke.getSize();
            expSymbolRotation = graphicStroke.getRotation();
            List<GraphicalSymbol> graphicSymbolList = graphicStroke.graphicalSymbols();
            for (GraphicalSymbol graphicSymbol : graphicSymbolList) {
                if (graphicSymbol instanceof MarkImpl) {
                    MarkImpl mark = (MarkImpl) graphicSymbol;
                    Mark defaultMark = getStyleFactory().getDefaultMark();
                    Fill markFill = mark.getFill();
                    if (markFill != null) {
                        expColour = markFill.getColor();
                    }
                    expStrokeColour = defaultMark.getStroke().getColor();
                    Stroke markStroke = mark.getStroke();
                    if (markStroke != null) {
                        expStrokeColour = markStroke.getColor();
                    }
                } else if (graphicSymbol instanceof ExternalGraphicImpl) {
                    @SuppressWarnings("unused") ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) graphicSymbol;
                }
                symbolTypeFactory.setValue(symbolizerType, this.fieldConfigManager, graphicStroke, graphicSymbol);
            }
        }
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_WIDTH, expStrokeWidth);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_OFFSET, expStrokeOffset);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_CAP, expStrokeLineCap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_JOIN, expStrokeLineJoin);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_DASH_ARRAY, expStrokeDashArray);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_GAP, expGap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_INITIAL_GAP, expInitialGap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_SIZE, expSymbolSize);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANGLE, expSymbolRotation);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_H, expAnchorPointX);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_V, expAnchorPointY);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_X, expDisplacementX);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_Y, expDisplacementY);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_FILL_COLOUR, expColour);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_STROKE_COLOUR, expStrokeColour);
        if ((graphicFill == null) && (graphicStroke == null)) {
            GroupConfigInterface fillColourGroup = getGroup(GroupIdEnum.FILLCOLOUR);
            if (fillColourGroup != null) {
                fillColourGroup.enable(true);
            }
        }
    // 
    // GroupConfigInterface strokeColourGroup = getGroup(GroupIdEnum.STROKECOLOUR);
    // if (strokeColourGroup != null) {
    // strokeColourGroup.enable(strokeColourEnabled);
    // }
    }
}
Also used : Fill(org.geotools.styling.Fill) GraphicStroke(org.opengis.style.GraphicStroke) Stroke(org.geotools.styling.Stroke) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.geotools.styling.Mark) MarkImpl(org.geotools.styling.MarkImpl) Displacement(org.geotools.styling.Displacement) AnchorPoint(org.geotools.styling.AnchorPoint) ConstantExpression(org.geotools.filter.ConstantExpression) Expression(org.opengis.filter.expression.Expression) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface)

Example 25 with Graphic

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

the class StrokeDetails method populate.

/**
 * Populate.
 *
 * @param selectedSymbol the selected symbol
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.selectedsymbol.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    Stroke stroke = null;
    if (selectedSymbol != null) {
        symbolizer = selectedSymbol.getSymbolizer();
        if (symbolizer instanceof PointSymbolizer) {
            PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
            Graphic graphic = pointSymbolizer.getGraphic();
            List<GraphicalSymbol> graphicalSymbols = graphic.graphicalSymbols();
            if (graphicalSymbols.size() > 0) {
                GraphicalSymbol symbol = graphicalSymbols.get(0);
                if (symbol instanceof MarkImpl) {
                    MarkImpl markerSymbol = (MarkImpl) symbol;
                    stroke = markerSymbol.getStroke();
                }
            }
        } else if (symbolizer instanceof LineSymbolizer) {
            LineSymbolizer lineSymbol = (LineSymbolizer) symbolizer;
            stroke = lineSymbol.getStroke();
        } else if (symbolizer instanceof PolygonSymbolizer) {
            PolygonSymbolizer polygonSymbol = (PolygonSymbolizer) symbolizer;
            stroke = polygonSymbol.getStroke();
        }
    }
    Class<?> symbolizerClass = null;
    if (symbolizer != null) {
        symbolizerClass = symbolizer.getClass();
    }
    populateStroke(symbolizerClass, stroke);
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) GraphicStroke(org.opengis.style.GraphicStroke) Stroke(org.geotools.styling.Stroke) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) LineSymbolizer(org.geotools.styling.LineSymbolizer) MarkImpl(org.geotools.styling.MarkImpl)

Aggregations

Graphic (org.geotools.styling.Graphic)34 PointSymbolizer (org.geotools.styling.PointSymbolizer)17 GraphicalSymbol (org.opengis.style.GraphicalSymbol)16 Fill (org.geotools.styling.Fill)13 Expression (org.opengis.filter.expression.Expression)12 ExternalGraphic (org.geotools.styling.ExternalGraphic)11 Stroke (org.geotools.styling.Stroke)10 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)9 AnchorPoint (org.geotools.styling.AnchorPoint)8 Displacement (org.geotools.styling.Displacement)8 ArrayList (java.util.ArrayList)7 Mark (org.geotools.styling.Mark)7 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)6 MarkImpl (org.geotools.styling.MarkImpl)6 Rule (org.geotools.styling.Rule)6 JsonObject (com.google.gson.JsonObject)5 LineSymbolizer (org.geotools.styling.LineSymbolizer)5 JsonElement (com.google.gson.JsonElement)4 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)4 NamedLayer (org.geotools.styling.NamedLayer)4