Search in sources :

Example 1 with Displacement

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

the class DetailsUtilitiesTest method testIsSameDisplacementDisplacement.

/**
 * Test method for {@link com.sldeditor.ui.detail.DetailsUtilities#isSame(org.geotools.styling.Displacement, org.geotools.styling.Displacement)}.
 */
@Test
public void testIsSameDisplacementDisplacement() {
    assertFalse(DetailsUtilities.isSame((Displacement) null, (Displacement) null));
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    // Try values that are the same
    Displacement displacement1 = new DisplacementImpl();
    displacement1.setDisplacementX(ff.literal(42));
    displacement1.setDisplacementY(ff.literal(-2));
    Displacement displacement2 = new DisplacementImpl();
    displacement2.setDisplacementX(ff.literal("42"));
    displacement2.setDisplacementY(ff.literal(-2));
    assertTrue(DetailsUtilities.isSame(displacement1, displacement2));
    // Try values that are not the same
    Displacement displacement3 = new DisplacementImpl();
    displacement3.setDisplacementX(ff.literal(1));
    displacement3.setDisplacementY(ff.literal(-2));
    assertFalse(DetailsUtilities.isSame(displacement1, displacement3));
    assertFalse(DetailsUtilities.isSame(displacement2, displacement3));
    Displacement displacement4 = new DisplacementImpl();
    displacement4.setDisplacementX(ff.literal((Long) 1L));
    displacement4.setDisplacementY(ff.literal(-2));
    assertFalse(DetailsUtilities.isSame(displacement1, displacement4));
    assertFalse(DetailsUtilities.isSame(displacement2, displacement4));
}
Also used : DisplacementImpl(org.geotools.styling.DisplacementImpl) Displacement(org.geotools.styling.Displacement) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 2 with Displacement

use of org.geotools.styling.Displacement 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 3 with Displacement

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

the class SimpleMarkerSymbol method convert.

/**
 * Convert.
 *
 * @param element the element
 * @return the graphic marker list
 */
@Override
public List<Graphic> convert(JsonElement element) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Graphic> markList = new ArrayList<Graphic>();
    double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
    double outlineSize = getDouble(obj, SimpleMarkerSymbolKeys.OUTLINE_SIZE);
    double size = getDouble(obj, CommonSymbolKeys.SIZE);
    int style = getInt(obj, CommonSymbolKeys.STYLE);
    double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
    double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
    Expression markerColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
    Expression outlineColour = getColour(obj.get(SimpleMarkerSymbolKeys.OUTLINE_COLOUR));
    Expression wellKnownName = ff.literal(styleMap.get(style));
    Stroke stroke = null;
    if (outlineSize > 0.0) {
        stroke = styleFactory.createStroke(outlineColour, ff.literal(outlineSize));
    }
    Fill fill = styleFactory.createFill(markerColour);
    Mark mark = styleFactory.createMark(wellKnownName, stroke, fill, ff.literal(size), ff.literal(angle));
    Expression expressionOpacity = null;
    ExternalGraphic[] externalGraphics = null;
    Symbol[] symbols = null;
    Mark[] marks = new Mark[1];
    marks[0] = mark;
    Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, expressionOpacity, ff.literal(size), ff.literal(angle));
    // Set offset
    if ((xOffset > 0.0) && (yOffset > 0.0)) {
        Displacement displacement = styleFactory.displacement(ff.literal(xOffset), ff.literal(yOffset));
        graphic.setDisplacement(displacement);
    }
    markList.add(graphic);
    return markList;
}
Also used : Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) 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)

Example 4 with Displacement

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

the class PolygonFillDetails method populate.

/**
 * Populate.
 *
 * @param selectedSymbol the selected symbol
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    Expression expSize = null;
    Expression expRotation = null;
    Expression expAnchorPointX = null;
    Expression expAnchorPointY = null;
    Expression expDisplacementX = null;
    Expression expDisplacementY = null;
    Expression expFillColour = null;
    Expression expGap = null;
    Expression expInitialGap = null;
    Fill fill = null;
    Expression expOpacity = null;
    symbolizer = null;
    if (selectedSymbol != null) {
        symbolizer = selectedSymbol.getSymbolizer();
        Graphic graphic = null;
        if (symbolizer instanceof PointSymbolizerImpl) {
            PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
            graphic = pointSymbolizer.getGraphic();
            if (graphic != null) {
                List<GraphicalSymbol> graphicSymbolList = graphic.graphicalSymbols();
                if (!graphicSymbolList.isEmpty()) {
                    GraphicalSymbol graphicalSymbol = graphicSymbolList.get(0);
                    if (graphicalSymbol instanceof MarkImpl) {
                        MarkImpl mark = (MarkImpl) graphicalSymbol;
                        fill = mark.getFill();
                        if (fill != null) {
                            expOpacity = fill.getOpacity();
                        }
                    }
                }
            }
        } else if (symbolizer instanceof PolygonSymbolizerImpl) {
            PolygonSymbolizer polygonSymbolizer = (PolygonSymbolizer) symbolizer;
            if (polygonSymbolizer != null) {
                fill = polygonSymbolizer.getFill();
                if (fill != null) {
                    expOpacity = fill.getOpacity();
                    graphic = fill.getGraphicFill();
                }
            }
        }
        if (graphic == null) {
            if (fill != null) {
                expFillColour = fill.getColor();
            }
            if (fill == null) {
                symbolTypeFactory.setNoFill(this.fieldConfigManager);
            } else {
                symbolTypeFactory.setSolidFill(this.fieldConfigManager, expFillColour, expOpacity);
            }
        } else {
            expSize = graphic.getSize();
            expRotation = graphic.getRotation();
            // Anchor point
            AnchorPoint anchorPoint = graphic.getAnchorPoint();
            if (anchorPoint != null) {
                expAnchorPointX = anchorPoint.getAnchorPointX();
                expAnchorPointY = anchorPoint.getAnchorPointY();
            } else {
                expAnchorPointX = defaultAnchorPoint.getAnchorPointX();
                expAnchorPointY = defaultAnchorPoint.getAnchorPointY();
            }
            // Offset
            Displacement displacement = graphic.getDisplacement();
            if (displacement != null) {
                expDisplacementX = displacement.getDisplacementX();
                expDisplacementY = displacement.getDisplacementY();
            } else {
                expDisplacementX = defaultDisplacement.getDisplacementX();
                expDisplacementY = defaultDisplacement.getDisplacementY();
            }
            expGap = graphic.getGap();
            expInitialGap = graphic.getInitialGap();
            List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
            if (!graphicalSymbolList.isEmpty()) {
                GraphicalSymbol symbol = graphicalSymbolList.get(0);
                symbolTypeFactory.setValue(PolygonSymbolizer.class, this.fieldConfigManager, graphic, symbol);
            }
        }
    }
    fieldConfigVisitor.populateField(FieldIdEnum.SIZE, expSize);
    fieldConfigVisitor.populateField(FieldIdEnum.ANGLE, expRotation);
    fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_H, expAnchorPointX);
    fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_V, expAnchorPointY);
    fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_X, expDisplacementX);
    fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_Y, expDisplacementY);
    fieldConfigVisitor.populateField(FieldIdEnum.GAP, expGap);
    fieldConfigVisitor.populateField(FieldIdEnum.INITIAL_GAP, expInitialGap);
    fieldConfigVisitor.populateField(FieldIdEnum.OVERALL_OPACITY, expOpacity);
    if (vendorOptionFillFactory != null) {
        if (symbolizer instanceof PolygonSymbolizer) {
            vendorOptionFillFactory.populate((PolygonSymbolizer) symbolizer);
        }
    }
    updateSymbol();
}
Also used : PolygonSymbolizerImpl(org.geotools.styling.PolygonSymbolizerImpl) PointSymbolizer(org.geotools.styling.PointSymbolizer) Fill(org.geotools.styling.Fill) GraphicFill(org.opengis.style.GraphicFill) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) MarkImpl(org.geotools.styling.MarkImpl) PointSymbolizerImpl(org.geotools.styling.PointSymbolizerImpl) Displacement(org.geotools.styling.Displacement)

Example 5 with Displacement

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

the class PolygonFillDetails method getGraphicFill.

/**
 * Gets the graphic fill.
 *
 * @return the graphic fill
 */
private GraphicFill getGraphicFill() {
    GroupConfigInterface fillGroup = getGroup(GroupIdEnum.FILL);
    boolean hasFill = fillGroup.isPanelEnabled();
    GroupConfigInterface strokeGroup = getGroup(GroupIdEnum.STROKE);
    boolean hasStroke = (strokeGroup == null) ? false : strokeGroup.isPanelEnabled();
    Expression opacity = null;
    Expression size = fieldConfigVisitor.getExpression(FieldIdEnum.SIZE);
    Expression rotation = fieldConfigVisitor.getExpression(FieldIdEnum.ANGLE);
    Expression symbolType = fieldConfigVisitor.getExpression(FieldIdEnum.SYMBOL_TYPE);
    // 
    // Anchor point
    // 
    AnchorPoint anchorPoint = null;
    GroupConfigInterface anchorPointPanel = getGroup(GroupIdEnum.ANCHORPOINT);
    if (anchorPointPanel.isPanelEnabled()) {
        anchorPoint = (AnchorPoint) getStyleFactory().anchorPoint(fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_H), fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_V));
        // default so it doesn't appear in the SLD
        if (DetailsUtilities.isSame(defaultAnchorPoint, anchorPoint)) {
            anchorPoint = null;
        }
    }
    // 
    // Displacement
    // 
    Displacement displacement = null;
    GroupConfigInterface displacementPanel = getGroup(GroupIdEnum.DISPLACEMENT);
    if (displacementPanel.isPanelEnabled()) {
        displacement = getStyleFactory().displacement(fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_X), fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_Y));
        // it doesn't appear in the SLD
        if (DetailsUtilities.isSame(defaultDisplacement, displacement)) {
            displacement = null;
        }
    }
    List<GraphicalSymbol> symbols = symbolTypeFactory.getValue(this.fieldConfigManager, symbolType, hasFill, hasStroke, selectedFillPanelId);
    GraphicFill graphicFill = getStyleFactory().graphicFill(symbols, opacity, size, rotation, anchorPoint, displacement);
    return graphicFill;
}
Also used : AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) GraphicFill(org.opengis.style.GraphicFill) GraphicalSymbol(org.opengis.style.GraphicalSymbol) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) Displacement(org.geotools.styling.Displacement)

Aggregations

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