Search in sources :

Example 1 with StyledLayer

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

the class MXDParser method processLabelRenderer.

/**
 * Gets the label renderer.
 *
 * @param sld the sld
 * @param labelRenderArrayElement the label render array element
 * @param transparency the transparency
 */
private void processLabelRenderer(StyledLayerDescriptor sld, JsonArray labelRenderArrayElement, int transparency) {
    if (sld != null) {
        if (labelRenderArrayElement != null) {
            List<StyledLayer> styledLayers = sld.layers();
            if (!styledLayers.isEmpty()) {
                if (styledLayers.get(0) instanceof NamedLayer) {
                    NamedLayer namedLayer = (NamedLayer) styledLayers.get(0);
                    List<Style> styleList = namedLayer.styles();
                    if (!styleList.isEmpty()) {
                        List<FeatureTypeStyle> ftsList = styleList.get(0).featureTypeStyles();
                        if (!ftsList.isEmpty()) {
                            List<Rule> ruleList = ftsList.get(0).rules();
                            List<Rule> newLabelRuleList = new ArrayList<Rule>();
                            for (int index = 0; index < labelRenderArrayElement.size(); index++) {
                                JsonElement labelRenderElement = labelRenderArrayElement.get(index);
                                JsonObject renderer = labelRenderElement.getAsJsonObject();
                                boolean found = false;
                                for (String labelRendererType : labelRendererMap.keySet()) {
                                    JsonElement obj = renderer.get(labelRendererType);
                                    if (obj != null) {
                                        EsriLabelRendererInterface esriLabelRenderer = labelRendererMap.get(labelRendererType);
                                        if (esriLabelRenderer != null) {
                                            for (Rule rule : ruleList) {
                                                esriLabelRenderer.convert(newLabelRuleList, rule, obj, transparency);
                                            }
                                        }
                                        found = true;
                                        break;
                                    }
                                }
                                if (!found) {
                                    ConsoleManager.getInstance().error(this, "Unsupported label renderer : " + SymbolUtils.extractName(labelRenderElement));
                                }
                            }
                            ruleList.addAll(newLabelRuleList);
                        }
                    }
                }
            }
        }
    }
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) EsriLabelRendererInterface(com.sldeditor.exportdata.esri.label.EsriLabelRendererInterface) JsonElement(com.google.gson.JsonElement) 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 2 with StyledLayer

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

the class SLDUtils method findRule.

/**
 * Find rule.
 *
 * @param sld the sld
 * @param ruleToFind the rule to find
 * @param otherSLD the other SLD
 * @return the rule
 */
public static Rule findRule(StyledLayerDescriptor sld, Rule ruleToFind, StyledLayerDescriptor otherSLD) {
    if (sld != null) {
        List<StyledLayer> styledLayerList = sld.layers();
        if (styledLayerList != null) {
            int styledLayerIndex = 0;
            int styleIndex = 0;
            int ftsIndex = 0;
            int ruleIndex = 0;
            boolean isNamedLayer = true;
            for (StyledLayer styledLayer : styledLayerList) {
                List<Style> styleList = null;
                if (styledLayer instanceof NamedLayerImpl) {
                    NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                    styleList = namedLayerImpl.styles();
                    isNamedLayer = true;
                } else if (styledLayer instanceof UserLayerImpl) {
                    UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                    styleList = userLayerImpl.userStyles();
                    isNamedLayer = false;
                }
                if (styleList != null) {
                    styleIndex = 0;
                    for (Style style : styleList) {
                        ftsIndex = 0;
                        for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                            ruleIndex = 0;
                            for (Rule rule : fts.rules()) {
                                if (rule == ruleToFind) {
                                    return findEquivalentRule(otherSLD, styledLayerIndex, isNamedLayer, styleIndex, ftsIndex, ruleIndex);
                                }
                                ruleIndex++;
                            }
                            ftsIndex++;
                        }
                        styleIndex++;
                    }
                }
                styledLayerIndex++;
            }
        }
    }
    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 3 with StyledLayer

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

the class SelectedSymbol method hasOnlyOneRule.

/**
 * Checks for only one rule.
 *
 * @return true, if successful
 */
public boolean hasOnlyOneRule() {
    boolean oneRule = false;
    StyledLayer[] styledLayers = sld.getStyledLayers();
    int noOfRules = 0;
    if (styledLayers != null) {
        for (StyledLayer styledLayer : styledLayers) {
            List<Style> styleList = null;
            if (styledLayer instanceof NamedLayerImpl) {
                NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                styleList = namedLayerImpl.styles();
            } else if (styledLayer instanceof UserLayerImpl) {
                UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                styleList = userLayerImpl.userStyles();
            }
            if (styleList != null) {
                for (Style style : styleList) {
                    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                        noOfRules += fts.rules().size();
                    }
                }
            }
        }
    }
    oneRule = (noOfRules == 1);
    logger.debug(String.format("Number of rules : %d", noOfRules));
    return oneRule;
}
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)

Example 4 with StyledLayer

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

the class SelectedSymbol method replaceStyledLayer.

/**
 * Replace named layer.
 *
 * @param newNamedLayer the new named layer
 */
public void replaceStyledLayer(NamedLayer newNamedLayer) {
    if (this.sld == null) {
        return;
    }
    StyledLayer[] styledLayerList = this.sld.getStyledLayers();
    int indexFound = -1;
    int index = 0;
    StyledLayer oldNamedLayer = null;
    for (StyledLayer styledLayer : styledLayerList) {
        if (styledLayer == this.symbolData.getStyledLayer()) {
            oldNamedLayer = styledLayer;
            indexFound = index;
            break;
        } else {
            index++;
        }
    }
    if (indexFound > -1) {
        styledLayerList[indexFound] = newNamedLayer;
        this.sld.setStyledLayers(styledLayerList);
        setStyledLayer(newNamedLayer);
    }
    for (SLDTreeUpdatedInterface listener : treeUpdateListenerList) {
        listener.updateNode(oldNamedLayer, newNamedLayer);
    }
}
Also used : StyledLayer(org.geotools.styling.StyledLayer)

Example 5 with StyledLayer

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

the class SelectedSymbol method updateInternalData.

/**
 * Update internal data based on the supplied mask.
 *
 * @param maskValue the mask value
 */
private void updateInternalData(SelectedSymbolMask.SymbolMaskEnum maskValue) {
    SymbolData localSymbolData = new SymbolData();
    SelectedSymbolMask mask = new SelectedSymbolMask(maskValue);
    if (sld == null) {
        return;
    }
    StyledLayer[] styledLayers = sld.getStyledLayers();
    if (styledLayers != null) {
        localSymbolData.initialiseSelectedStyledLayerIndex();
        for (StyledLayer styledLayer : styledLayers) {
            localSymbolData.setStyledLayer(styledLayer);
            if (styledLayer == symbolData.getStyledLayer()) {
                this.symbolData.update(localSymbolData);
                return;
            }
            List<Style> styleList = null;
            if ((styledLayer instanceof NamedLayerImpl) && mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_STYLED_LAYER)) {
                NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                styleList = namedLayerImpl.styles();
            } else if ((styledLayer instanceof UserLayerImpl) && mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_STYLED_LAYER)) {
                UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                styleList = userLayerImpl.userStyles();
            }
            if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_STYLE) && (styleList != null)) {
                localSymbolData.initialiseSelectedStyleIndex();
                for (Style style : styleList) {
                    localSymbolData.setStyle(style);
                    if (style == symbolData.getStyle()) {
                        this.symbolData.update(localSymbolData);
                        return;
                    }
                    if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_FEATURE_TYPE_STYLE)) {
                        localSymbolData.initialiseSelectedFTSIndex();
                        for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                            localSymbolData.setFeatureTypeStyle(fts);
                            if (fts == symbolData.getFeatureTypeStyle()) {
                                this.symbolData.update(localSymbolData);
                                return;
                            }
                            if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_RULE)) {
                                localSymbolData.initialiseSelectedRuleIndex();
                                for (Rule rule : fts.rules()) {
                                    localSymbolData.setRule(rule);
                                    if (rule == symbolData.getRule()) {
                                        this.symbolData.update(localSymbolData);
                                        return;
                                    }
                                    if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_SYMBOLIZER)) {
                                        localSymbolData.initialiseSelectedSymbolizerIndex();
                                        for (Symbolizer symbol : rule.symbolizers()) {
                                            localSymbolData.setSymbolizer(symbol);
                                            if (symbol == this.symbolData.getSymbolizer()) {
                                                this.symbolData.update(localSymbolData);
                                                return;
                                            } else {
                                                localSymbolData.incrementSelectedSymbolizerIndex();
                                            }
                                        }
                                    }
                                    localSymbolData.incrementSelectedRuleIndex();
                                }
                            }
                            localSymbolData.incrementSelectedFTSIndex();
                        }
                    }
                    localSymbolData.incrementSelectedStyleIndex();
                }
            }
            localSymbolData.incrementSelectedStyledLayerIndex();
        }
    }
}
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) Symbolizer(org.geotools.styling.Symbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer)

Aggregations

StyledLayer (org.geotools.styling.StyledLayer)43 Style (org.geotools.styling.Style)28 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)25 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)22 Rule (org.geotools.styling.Rule)19 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)19 UserLayerImpl (org.geotools.styling.UserLayerImpl)16 Symbolizer (org.geotools.styling.Symbolizer)12 NamedLayer (org.geotools.styling.NamedLayer)10 Test (org.junit.Test)10 PointSymbolizer (org.geotools.styling.PointSymbolizer)9 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)7 LineSymbolizer (org.geotools.styling.LineSymbolizer)6 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)5 IOException (java.io.IOException)4 FeatureTypeConstraint (org.geotools.styling.FeatureTypeConstraint)4 SLDData (com.sldeditor.common.data.SLDData)3 ArrayList (java.util.ArrayList)3 UserLayer (org.geotools.styling.UserLayer)3 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)2