Search in sources :

Example 81 with FeatureTypeStyle

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

the class DefaultSymbols method createNewPolygon.

/**
 * Creates a new polygon symbol.
 *
 * @return the styled layer descriptor
 */
public static StyledLayerDescriptor createNewPolygon() {
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    fts.rules().add(rule);
    PolygonSymbolizer polygon = createDefaultPolygonSymbolizer();
    rule.symbolizers().add(polygon);
    return sld;
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer)

Example 82 with FeatureTypeStyle

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

the class SymbolizerDetailsPanel method getMinimumVersion.

/**
 * Gets the minimum version vendor option present in the SLD.
 *
 * @param parentObj the parent obj
 * @param sldObj the sld obj
 * @param vendorOptionsPresentList the vendor options present list
 */
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
    Class<?> parentClass = null;
    Class<?> classSelected = sldObj.getClass();
    if (sldObj instanceof StyledLayerDescriptor) {
    // No parent
    } else if (sldObj instanceof StyledLayer) {
        parentClass = StyledLayerDescriptor.class;
    } else if (sldObj instanceof Style) {
        parentClass = StyledLayer.class;
    } else if (sldObj instanceof FeatureTypeStyle) {
        parentClass = Style.class;
    } else if (sldObj instanceof Rule) {
        parentClass = FeatureTypeStyle.class;
    } else if (sldObj instanceof Symbolizer) {
        parentClass = Rule.class;
    }
    internal_getMinimumVersion(parentObj, sldObj, vendorOptionsPresentList, parentClass, classSelected);
    if (sldObj instanceof PointSymbolizerImpl) {
        PointSymbolizerImpl pointSymbolizer = (PointSymbolizerImpl) sldObj;
        parentClass = PointSymbolizerImpl.class;
        classSelected = FillImpl.class;
        internal_getMinimumVersion(pointSymbolizer, pointSymbolizer.getGraphic(), vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof LineSymbolizerImpl) {
        LineSymbolizerImpl lineSymbolizer = (LineSymbolizerImpl) sldObj;
        parentClass = LineSymbolizerImpl.class;
        classSelected = StrokeImpl.class;
        internal_getMinimumVersion(lineSymbolizer, lineSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof PolygonSymbolizerImpl) {
        PolygonSymbolizerImpl polygonSymbolizer = (PolygonSymbolizerImpl) sldObj;
        parentClass = PolygonSymbolizerImpl.class;
        classSelected = FillImpl.class;
        internal_getMinimumVersion(polygonSymbolizer, polygonSymbolizer.getFill(), vendorOptionsPresentList, parentClass, classSelected);
        classSelected = StrokeImpl.class;
        internal_getMinimumVersion(polygonSymbolizer, polygonSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof TextSymbolizerImpl) {
        TextSymbolizerImpl textSymbolizer = (TextSymbolizerImpl) sldObj;
        parentClass = Rule.class;
        classSelected = TextSymbolizerImpl.class;
        internal_getMinimumVersion(parentObj, textSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof RasterSymbolizerImpl) {
        RasterSymbolizerImpl rasterSymbolizer = (RasterSymbolizerImpl) sldObj;
        parentClass = Rule.class;
        classSelected = RasterSymbolizerImpl.class;
        internal_getMinimumVersion(parentObj, rasterSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
    }
}
Also used : TextSymbolizerImpl(org.geotools.styling.TextSymbolizerImpl) StyledLayer(org.geotools.styling.StyledLayer) LineSymbolizerImpl(org.geotools.styling.LineSymbolizerImpl) StrokeImpl(org.geotools.styling.StrokeImpl) Symbolizer(org.geotools.styling.Symbolizer) RasterSymbolizerImpl(org.geotools.styling.RasterSymbolizerImpl) PolygonSymbolizerImpl(org.geotools.styling.PolygonSymbolizerImpl) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) PointSymbolizerImpl(org.geotools.styling.PointSymbolizerImpl)

Example 83 with FeatureTypeStyle

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

the class RenderSymbol method renderSymbol.

/**
 * Render symbol.
 *
 * @param style the style
 * @param ftsToRender the fts to render
 * @param ruleToRender the rule to render
 * @param options the options
 * @return the style
 */
private Style renderSymbol(Style style, FeatureTypeStyle ftsToRender, Rule ruleToRender, RuleRenderOptions options) {
    int symbolIndex = SelectedSymbol.getInstance().getSymbolIndex();
    RuleRenderVisitor visitor = new RuleRenderVisitor(ftsToRender, ruleToRender, symbolIndex, options);
    style.accept(visitor);
    Style copy = (Style) visitor.getCopy();
    return copy;
}
Also used : Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Example 84 with FeatureTypeStyle

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

the class RenderSymbol method getRenderStyle.

/**
 * Gets the render style.
 *
 * @param selectedSymbol the selected symbol
 * @return the render style
 */
public Style getRenderStyle(SelectedSymbol selectedSymbol) {
    List<StyledLayer> styledLayerList = selectedSymbol.getSld().layers();
    for (StyledLayer styledLayer : styledLayerList) {
        List<Style> styleList = null;
        if (styledLayer instanceof NamedLayerImpl) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) styledLayer;
            styleList = namedLayer.styles();
        } else if (styledLayer instanceof UserLayerImpl) {
            UserLayerImpl userLayer = (UserLayerImpl) styledLayer;
            styleList = userLayer.userStyles();
        }
        if (styleList != null) {
            for (Style style : styleList) {
                FeatureTypeStyle ftsToRender = selectedSymbol.getFeatureTypeStyle();
                Rule ruleToRender = selectedSymbol.getRule();
                // Check to see if style contains the rule to render
                if (shouldRenderSymbol(style, ftsToRender, ruleToRender)) {
                    return renderSymbol(style, ftsToRender, ruleToRender, renderOptions);
                }
            }
        }
    }
    return null;
}
Also used : UserLayerImpl(org.geotools.styling.UserLayerImpl) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 85 with FeatureTypeStyle

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

the class LegendManager method createLegend.

/**
 * Creates the legend.
 *
 * @param sld the sld
 * @param heading the heading
 * @param filename the filename
 * @param separateSymbolizers the separate symbolizers
 * @return the map
 */
public Map<String, BufferedImage> createLegend(StyledLayerDescriptor sld, String heading, String filename, boolean separateSymbolizers) {
    Map<String, BufferedImage> imageMap = new HashMap<String, BufferedImage>();
    // 
    // Set legend options
    // 
    Map<String, Object> legendOptions = new HashMap<String, Object>();
    if (heading != null) {
        legendOptions.put("heading", heading);
    }
    if (filename != null) {
        legendOptions.put("filename", filename);
    }
    if (legendOptionData == null) {
        legendOptionData = new LegendOptionData();
    }
    GetLegendGraphicRequest request = new GetLegendGraphicRequest();
    request.setWidth(legendOptionData.getImageWidth());
    request.setHeight(legendOptionData.getImageHeight());
    request.setTransparent(legendOptionData.isTransparent());
    request.setStrict(false);
    legendOptions.put("bgColor", ColourUtils.fromColour(legendOptionData.getBackgroundColour()));
    legendOptions.put("fontColor", ColourUtils.fromColour(legendOptionData.getLabelFontColour()));
    // 
    // Label Font
    // 
    Font font = legendOptionData.getLabelFont();
    legendOptions.put("fontName", font.getFontName());
    String styleValue = null;
    if ((font.getStyle() & java.awt.Font.BOLD) == java.awt.Font.BOLD) {
        styleValue = "bold";
    }
    if ((font.getStyle() & java.awt.Font.ITALIC) == java.awt.Font.ITALIC) {
        styleValue = "italic";
    }
    if (styleValue != null) {
        legendOptions.put("fontStyle", styleValue);
    }
    legendOptions.put("fontSize", String.valueOf(font.getSize()));
    legendOptions.put("dpi", Integer.valueOf(legendOptionData.getDpi()));
    legendOptions.put("fontAntiAliasing", getBooleanValueOnOff(legendOptionData.isFontAntiAliasing()));
    legendOptions.put("forceLabels", getBooleanValueOnOff(legendOptionData.isShowLabels()));
    legendOptions.put("forceTitles", getBooleanValueOnOff(legendOptionData.isShowTitle()));
    legendOptions.put("bandInfo", getBooleanValueTrueFalse(legendOptionData.isBandInformation()));
    legendOptions.put("border", getBooleanValueTrueFalse(legendOptionData.isBorder()));
    legendOptions.put("borderColor", ColourUtils.fromColour(legendOptionData.getBorderColour()));
    legendOptions.put("imageSizeFactor", String.valueOf(legendOptionData.getImageSize() / 100.0));
    request.setLegendOptions(legendOptions);
    if (sld != null) {
        Map<String, Style> styleMap = new LinkedHashMap<String, Style>();
        StyledLayer selectedStyledLayer = SelectedSymbol.getInstance().getStyledLayer();
        Style selectedStyle = SelectedSymbol.getInstance().getStyle();
        if (selectedStyle != null) {
            createSingleStyleLegend(styleMap, selectedStyledLayer, selectedStyle);
        } else {
            createMultipleStyleLegend(sld, styleMap, selectedStyledLayer);
        }
        // Merge symbolizers into 1 image
        if (!separateSymbolizers) {
            for (String key : styleMap.keySet()) {
                Style style = styleMap.get(key);
                if (!style.featureTypeStyles().isEmpty()) {
                    FeatureTypeStyle featureTypeStyle = style.featureTypeStyles().get(0);
                    if (featureTypeStyle != null) {
                        if (!featureTypeStyle.rules().isEmpty()) {
                            LegendRequest legendEntryRequest = request.new LegendRequest();
                            request.getLegends().add(legendEntryRequest);
                            legendEntryRequest.setTitle(key);
                            legendEntryRequest.setStyle(style);
                        }
                    }
                }
            }
            BufferedImage legendGraphic = null;
            try {
                legendGraphic = legendBuilder.buildLegendGraphic(request);
            } catch (Exception e) {
            // Ignore
            }
            imageMap.put("", legendGraphic);
        } else {
            for (String key : styleMap.keySet()) {
                request.getLegends().clear();
                LegendRequest legendEntryRequest = request.new LegendRequest();
                legendEntryRequest.setStyle(styleMap.get(key));
                legendEntryRequest.setStyleName(key);
                request.getLegends().add(legendEntryRequest);
                BufferedImage legendGraphic = null;
                try {
                    legendGraphic = legendBuilder.buildLegendGraphic(request);
                } catch (Exception e) {
                // Ignore
                }
                imageMap.put(key, legendGraphic);
            }
        }
    }
    return imageMap;
}
Also used : GetLegendGraphicRequest(org.geoserver.wms.GetLegendGraphicRequest) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StyledLayer(org.geotools.styling.StyledLayer) LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) IIOInvalidTreeException(javax.imageio.metadata.IIOInvalidTreeException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) LegendRequest(org.geoserver.wms.GetLegendGraphicRequest.LegendRequest)

Aggregations

FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)110 Style (org.geotools.styling.Style)81 Rule (org.geotools.styling.Rule)65 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)43 Test (org.junit.Test)42 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)24 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)21 LineSymbolizer (org.geotools.styling.LineSymbolizer)20 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)17 Symbolizer (org.geotools.styling.Symbolizer)16 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)15 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)14 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)12 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)12 TextSymbolizer (org.geotools.styling.TextSymbolizer)12 UserLayerImpl (org.geotools.styling.UserLayerImpl)12 ArrayList (java.util.ArrayList)11 LineStyle (org.polymap.core.style.model.feature.LineStyle)11