Search in sources :

Example 1 with NamedLayer

use of org.geotools.styling.NamedLayer 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 NamedLayer

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

the class SimpleRenderer method convert.

/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.renderer.EsriRendererInterface#convert(com.google.gson.JsonObject, java.lang.String, double, double, int)
     */
@Override
public StyledLayerDescriptor convert(JsonObject json, String layerName, double minScale, double maxScale, int transparency) {
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    String label = json.get(CommonRendererKeys.LABEL).getAsString();
    namedLayer.setName(label);
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    // style.setAbstract(json.get(IntermediateFileKeys.DESCRIPTION).getAsString());
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    if (minScale > 0.0) {
        rule.setMinScaleDenominator(minScale);
    }
    if (maxScale > 0.0) {
        rule.setMaxScaleDenominator(maxScale);
    }
    JsonElement jsonElement = json.get(CommonRendererKeys.SYMBOL);
    rule.setName(label);
    SymbolManager.getInstance().convertSymbols(rule, layerName, transparency, jsonElement);
    fts.rules().add(rule);
    return sld;
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) 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 3 with NamedLayer

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

the class UniqueValueRenderer method convert.

/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.renderer.EsriRendererInterface#convert(com.google.gson.JsonObject, java.lang.String, double, double, int)
     */
@Override
public StyledLayerDescriptor convert(JsonObject json, String layerName, double minScale, double maxScale, int transparency) {
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    boolean useDefaultSymbol = false;
    JsonElement useDefaultSymbolElement = json.get(UniqueValueRendererKeys.USE_DEFAULTSYMBOL);
    if (useDefaultSymbolElement != null) {
        useDefaultSymbol = useDefaultSymbolElement.getAsBoolean();
    }
    JsonElement jsonElement = json.get(CommonRendererKeys.LABEL);
    if (jsonElement != null) {
        namedLayer.setName(jsonElement.getAsString());
    }
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    // style.setAbstract(json.get(IntermediateFileKeys.DESCRIPTION).getAsString());
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    JsonElement element = json.get(UniqueValueRendererKeys.VALUES);
    if (element != null) {
        JsonArray valueList = element.getAsJsonArray();
        for (int index = 0; index < valueList.size(); index++) {
            JsonElement valueElement = valueList.get(index);
            if (valueElement != null) {
                Rule rule = styleFactory.createRule();
                JsonObject valueObj = valueElement.getAsJsonObject();
                String value = getString(valueObj, UniqueValueRendererKeys.VALUES_VALUE);
                String label = getString(valueObj, UniqueValueRendererKeys.VALUES_LABEL);
                rule.setName(label);
                createFilter(rule, json.get(UniqueValueRendererKeys.FIELDS), json.get(UniqueValueRendererKeys.FIELD_DELIMETER), value);
                // Heading /description
                String heading = getString(valueObj, UniqueValueRendererKeys.VALUES_HEADING);
                @SuppressWarnings("unused") String description = getString(valueObj, UniqueValueRendererKeys.VALUES_DESCRIPTION);
                if ((heading != null) && !heading.isEmpty() || (label != null) && !label.isEmpty()) {
                    if (label == null) {
                        label = "";
                    }
                    InternationalString titleString = Text.text(label);
                    if (heading == null) {
                        heading = "";
                    }
                    InternationalString descriptionString = Text.text(heading);
                    Description descriptionObj = styleFactory.description(titleString, descriptionString);
                    rule.setDescription(descriptionObj);
                }
                if (minScale > 0.0) {
                    rule.setMinScaleDenominator(minScale);
                }
                if (maxScale > 0.0) {
                    rule.setMaxScaleDenominator(maxScale);
                }
                JsonElement jsonSymbolElement = valueObj.get(UniqueValueRendererKeys.VALUES_SYMBOL);
                SymbolManager.getInstance().convertSymbols(rule, layerName, transparency, jsonSymbolElement);
                if (useDefaultSymbol && value == null) {
                    rule.setIsElseFilter(true);
                }
                fts.rules().add(rule);
            }
        }
    }
    return sld;
}
Also used : Description(org.geotools.styling.Description) JsonObject(com.google.gson.JsonObject) InternationalString(org.opengis.util.InternationalString) JsonArray(com.google.gson.JsonArray) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) InternationalString(org.opengis.util.InternationalString) 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 4 with NamedLayer

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

the class StrokeDetailsTest method testStrokeDetailsPolygon.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testStrokeDetailsPolygon() {
    StrokeDetails panel = new StrokeDetails();
    panel.populate(null);
    // Set up test data
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    SelectedSymbol.getInstance().createNewSLD(sld);
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    String expectedNameLayerValue = "named layer test value";
    namedLayer.setName(expectedNameLayerValue);
    Style style = DefaultSymbols.createNewStyle();
    String expectedNameStyleValue = "style test value";
    style.setName(expectedNameStyleValue);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedNameFTSValue = "feature type style test value";
    fts.setName(expectedNameFTSValue);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    String expectedNameValue = "rule test value";
    rule.setName(expectedNameValue);
    PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    rule.symbolizers().add(symbolizer);
    fts.rules().add(rule);
    sld.layers().add(namedLayer);
    SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyle(style);
    SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
    SelectedSymbol.getInstance().setRule(rule);
    SelectedSymbol.getInstance().setSymbolizer(symbolizer);
    panel.populate(SelectedSymbol.getInstance());
    GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
    assertNotNull(fieldDataManager);
    FieldConfigSymbolType symbolTypeField = (FieldConfigSymbolType) fieldDataManager.get(FieldIdEnum.STROKE_STYLE);
    symbolTypeField.populateField("circle");
    double expectedAngle = 14.5;
    FieldConfigDouble angleField = (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.STROKE_SYMBOL_ANGLE);
    angleField.populateField(expectedAngle);
    FieldConfigSlider opacityField = (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
    double opacity = 0.15;
    opacityField.populateField(opacity);
    FieldConfigString dashField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.STROKE_DASH_ARRAY);
    String dashArray = "1 2";
    dashField.populateField(dashArray);
    panel.dataChanged(null);
    double actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
    assertTrue(panel.isDataPresent());
    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - opacity) < 0.01);
    // Reset to default value
    panel.preLoadSymbol();
    actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 0.0) < 0.01);
    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 1.0) < 0.01);
}
Also used : FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) StrokeDetails(com.sldeditor.ui.detail.StrokeDetails) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) FieldConfigSlider(com.sldeditor.ui.detail.config.FieldConfigSlider) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) 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) NamedLayer(org.geotools.styling.NamedLayer) FieldConfigSymbolType(com.sldeditor.ui.detail.config.FieldConfigSymbolType) Test(org.junit.Test)

Example 5 with NamedLayer

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

the class StrokeDetailsTest method testStrokeDetailsCircle.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testStrokeDetailsCircle() {
    StrokeDetails panel = new StrokeDetails();
    panel.populate(null);
    // Set up test data
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    SelectedSymbol.getInstance().createNewSLD(sld);
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    String expectedNameLayerValue = "named layer test value";
    namedLayer.setName(expectedNameLayerValue);
    Style style = DefaultSymbols.createNewStyle();
    String expectedNameStyleValue = "style test value";
    style.setName(expectedNameStyleValue);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedNameFTSValue = "feature type style test value";
    fts.setName(expectedNameFTSValue);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    String expectedNameValue = "rule test value";
    rule.setName(expectedNameValue);
    PointSymbolizer symbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    rule.symbolizers().add(symbolizer);
    fts.rules().add(rule);
    sld.layers().add(namedLayer);
    SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyle(style);
    SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
    SelectedSymbol.getInstance().setRule(rule);
    SelectedSymbol.getInstance().setSymbolizer(symbolizer);
    panel.populate(SelectedSymbol.getInstance());
    GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
    assertNotNull(fieldDataManager);
    FieldConfigSymbolType symbolTypeField = (FieldConfigSymbolType) fieldDataManager.get(FieldIdEnum.STROKE_STYLE);
    symbolTypeField.populateField("circle");
    double expectedAngle = 14.5;
    FieldConfigDouble angleField = (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.STROKE_SYMBOL_ANGLE);
    angleField.populateField(expectedAngle);
    FieldConfigSlider opacityField = (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
    double opacity = 0.15;
    opacityField.populateField(opacity);
    FieldConfigString dashField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.STROKE_DASH_ARRAY);
    String dashArray = "1 2";
    dashField.populateField(dashArray);
    panel.dataChanged(null);
    double actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
    assertFalse(panel.isDataPresent());
    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - opacity) < 0.01);
    // Reset to default value
    panel.preLoadSymbol();
    actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 0.0) < 0.01);
    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 1.0) < 0.01);
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) StrokeDetails(com.sldeditor.ui.detail.StrokeDetails) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) FieldConfigSlider(com.sldeditor.ui.detail.config.FieldConfigSlider) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) 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) NamedLayer(org.geotools.styling.NamedLayer) FieldConfigSymbolType(com.sldeditor.ui.detail.config.FieldConfigSymbolType) Test(org.junit.Test)

Aggregations

NamedLayer (org.geotools.styling.NamedLayer)51 Style (org.geotools.styling.Style)44 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)44 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)42 Rule (org.geotools.styling.Rule)38 Test (org.junit.Test)34 PointSymbolizer (org.geotools.styling.PointSymbolizer)16 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)15 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)13 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)13 LineSymbolizer (org.geotools.styling.LineSymbolizer)11 StyledLayer (org.geotools.styling.StyledLayer)10 Symbolizer (org.geotools.styling.Symbolizer)8 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)7 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)7 SLDData (com.sldeditor.common.data.SLDData)6 TextSymbolizer (org.geotools.styling.TextSymbolizer)6 FilterFactory (org.opengis.filter.FilterFactory)6 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)5 FieldConfigDouble (com.sldeditor.ui.detail.config.FieldConfigDouble)5