Search in sources :

Example 1 with Description

use of org.geotools.styling.Description 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 2 with Description

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

the class DefaultSymbols method createDefaultTextSymbolizer.

/**
 * Creates the default text symbolizer.
 *
 * @return the text symbolizer
 */
public static TextSymbolizer createDefaultTextSymbolizer() {
    Expression fontFamily = ff.literal("Serif");
    Expression fontSize = ff.literal(10.0);
    Expression fontStyle = ff.literal("normal");
    Expression fontWeight = ff.literal("normal");
    Expression rotation = ff.literal(0.0);
    Expression label = ff.literal("Test");
    String geometryFieldName = null;
    Expression geometryField = ff.property(geometryFieldName);
    String name = Localisation.getString(SLDTreeTools.class, "TreeItem.newText");
    AnchorPoint anchor = null;
    Displacement displacement = null;
    PointPlacement pointPlacement = (PointPlacement) styleFactory.pointPlacement(anchor, displacement, rotation);
    Expression fillColour = ff.literal(DEFAULT_COLOUR);
    Expression fillColourOpacity = ff.literal(1.0);
    Fill fill = styleFactory.fill(null, fillColour, fillColourOpacity);
    Halo halo = null;
    List<Expression> fontFamilyList = new ArrayList<Expression>();
    fontFamilyList.add(fontFamily);
    Font font = (Font) styleFactory.font(fontFamilyList, fontStyle, fontWeight, fontSize);
    Description description = null;
    Unit<Length> unit = null;
    TextSymbolizer newTextSymbolizer = (TextSymbolizer) styleFactory.textSymbolizer(name, geometryField, description, unit, label, font, pointPlacement, halo, fill);
    return newTextSymbolizer;
}
Also used : PointPlacement(org.geotools.styling.PointPlacement) Fill(org.geotools.styling.Fill) Description(org.geotools.styling.Description) ArrayList(java.util.ArrayList) Displacement(org.opengis.style.Displacement) Font(org.geotools.styling.Font) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) Length(javax.measure.quantity.Length) TextSymbolizer(org.geotools.styling.TextSymbolizer) Halo(org.geotools.styling.Halo)

Example 3 with Description

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

the class StandardPanel method populateStandardData.

/**
 * Populate standard data.
 *
 * @param standardData the standard data
 */
private void populateStandardData(StandardData standardData) {
    Description description = standardData.description;
    String titleString = "";
    String descriptionString = "";
    if (description != null) {
        InternationalString title = description.getTitle();
        if (title != null) {
            titleString = title.toString();
        }
        InternationalString abstractDesc = description.getAbstract();
        if (abstractDesc != null) {
            descriptionString = abstractDesc.toString();
        }
    }
    if (fieldConfigVisitor.getFieldConfig(FieldIdEnum.NAME) != null) {
        fieldConfigVisitor.populateTextField(FieldIdEnum.NAME, standardData.name);
    }
    if (fieldConfigVisitor.getFieldConfig(FieldIdEnum.TITLE) != null) {
        fieldConfigVisitor.populateTextField(FieldIdEnum.TITLE, titleString);
    }
    if (fieldConfigVisitor.getFieldConfig(FieldIdEnum.DESCRIPTION) != null) {
        fieldConfigVisitor.populateTextField(FieldIdEnum.DESCRIPTION, descriptionString);
    }
    FieldConfigBase uomFieldConfig = fieldConfigManager.get(FieldIdEnum.UOM);
    if (uomFieldConfig != null) {
        uomFieldConfig.updateAttributeSelection(SelectedSymbol.getInstance().isRasterSymbol());
        String uomString = UnitsOfMeasure.getInstance().convert(standardData.unit);
        fieldConfigVisitor.populateField(FieldIdEnum.UOM, getFilterFactory().literal(uomString));
    }
}
Also used : Description(org.geotools.styling.Description) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) InternationalString(org.opengis.util.InternationalString) InternationalString(org.opengis.util.InternationalString)

Aggregations

Description (org.geotools.styling.Description)3 InternationalString (org.opengis.util.InternationalString)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)1 ArrayList (java.util.ArrayList)1 Length (javax.measure.quantity.Length)1 AnchorPoint (org.geotools.styling.AnchorPoint)1 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)1 Fill (org.geotools.styling.Fill)1 Font (org.geotools.styling.Font)1 Halo (org.geotools.styling.Halo)1 NamedLayer (org.geotools.styling.NamedLayer)1 PointPlacement (org.geotools.styling.PointPlacement)1 Rule (org.geotools.styling.Rule)1 Style (org.geotools.styling.Style)1 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)1 TextSymbolizer (org.geotools.styling.TextSymbolizer)1 Expression (org.opengis.filter.expression.Expression)1