Search in sources :

Example 56 with Symbolizer

use of org.geotools.styling.Symbolizer 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 57 with Symbolizer

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

the class PointSymbolizerDetails method populate.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.selectedsymbol.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    if (selectedSymbol != null) {
        Symbolizer symbolizer = selectedSymbol.getSymbolizer();
        populateStandardData(symbolizer);
        fieldConfigVisitor.populateField(FieldIdEnum.GEOMETRY, symbolizer.getGeometry());
    }
    updateSymbol();
}
Also used : Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer)

Example 58 with Symbolizer

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

the class RasterSymbolizerDetails method updateSymbol.

/**
 * Update symbol.
 */
private void updateSymbol() {
    // Contrast enhancement
    Expression gammaValueExpression = fieldConfigVisitor.getExpression(FieldIdEnum.RASTER_CONTRAST_GAMMAVALUE);
    ContrastEnhancement contrastEnhancement = null;
    GroupConfigInterface group = getGroup(GroupIdEnum.RASTER_CONTRAST);
    if (group.isPanelEnabled()) {
        String method = null;
        group = getGroup(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD);
        if (group != null) {
            MultiOptionGroup contrastNormalizeMethodGroup = (MultiOptionGroup) group;
            OptionGroup selectedOption = contrastNormalizeMethodGroup.getSelectedOptionGroup();
            if (selectedOption != null) {
                method = selectedOption.getLabel();
            }
        }
        contrastEnhancement = (ContrastEnhancement) getStyleFactory().contrastEnhancement(gammaValueExpression, method);
    }
    // Colour map
    ColorMap colorMap = fieldConfigVisitor.getColourMap(FieldIdEnum.RASTER_COLOURMAP);
    ValueComboBoxData colourMapType = fieldConfigVisitor.getComboBox(FieldIdEnum.RASTER_COLOURMAP_TYPE);
    colorMap.setType(Integer.valueOf(colourMapType.getKey()));
    // Channel selection
    ChannelSelection channelSelection = null;
    group = getGroup(GroupIdEnum.RASTER_CHANNELSELECTION);
    if (group != null) {
        if (group.isPanelEnabled()) {
            MultiOptionGroup contrastEnhancementGroup = (MultiOptionGroup) group;
            OptionGroup selectedOption = contrastEnhancementGroup.getSelectedOptionGroup();
            if (selectedOption.getId() == GroupIdEnum.RASTER_GREY_CHANNEL_OPTION) {
                // Grey option group
                SelectedChannelType greyChannel = extractContrastEnhancementGroup(GroupIdEnum.RASTER_GREY_CHANNEL, FieldIdEnum.RASTER_RGB_GREY_NAME, GroupIdEnum.RASTER_RGB_CHANNEL_GREY_CONTRAST, FieldIdEnum.RASTER_RGB_CHANNEL_GREY_CONTRAST_GAMMA, GroupIdEnum.RASTER_RGB_CHANNEL_GREY_CONTRAST_METHOD);
                channelSelection = getStyleFactory().channelSelection(greyChannel);
            } else {
                SelectedChannelType redChannel = extractContrastEnhancementGroup(GroupIdEnum.RASTER_RGB_CHANNEL_RED, FieldIdEnum.RASTER_RGB_RED_NAME, GroupIdEnum.RASTER_RGB_CHANNEL_RED_CONTRAST, FieldIdEnum.RASTER_RGB_CHANNEL_RED_CONTRAST_GAMMA, GroupIdEnum.RASTER_RGB_CHANNEL_RED_CONTRAST_METHOD);
                SelectedChannelType greenChannel = extractContrastEnhancementGroup(GroupIdEnum.RASTER_RGB_CHANNEL_GREEN, FieldIdEnum.RASTER_RGB_GREEN_NAME, GroupIdEnum.RASTER_RGB_CHANNEL_GREEN_CONTRAST, FieldIdEnum.RASTER_RGB_CHANNEL_GREEN_CONTRAST_GAMMA, GroupIdEnum.RASTER_RGB_CHANNEL_GREEN_CONTRAST_METHOD);
                SelectedChannelType blueChannel = extractContrastEnhancementGroup(GroupIdEnum.RASTER_RGB_CHANNEL_BLUE, FieldIdEnum.RASTER_RGB_BLUE_NAME, GroupIdEnum.RASTER_RGB_CHANNEL_BLUE_CONTRAST, FieldIdEnum.RASTER_RGB_CHANNEL_BLUE_CONTRAST_GAMMA, GroupIdEnum.RASTER_RGB_CHANNEL_BLUE_CONTRAST_METHOD);
                SelectedChannelType[] channels = new SelectedChannelType[3];
                channels[0] = redChannel;
                channels[1] = greenChannel;
                channels[2] = blueChannel;
                channelSelection = getStyleFactory().createChannelSelection(channels);
            }
        }
    }
    // 
    // Overlap
    // 
    OverlapBehavior overlapBehavior = null;
    group = getGroup(GroupIdEnum.RASTER_OVERLAP);
    if (group.isPanelEnabled()) {
        ValueComboBoxData overlapBehaviorValue = fieldConfigVisitor.getComboBox(FieldIdEnum.RASTER_OVERLAP_BEHAVIOUR);
        overlapBehavior = OverlapBehavior.valueOf(overlapBehaviorValue.getKey());
    }
    // 
    // Shaded relief
    // 
    ShadedRelief shadedRelief = null;
    group = getGroup(GroupIdEnum.RASTER_SHADEDRELIEF);
    if (group.isPanelEnabled()) {
        shadedRelief = new ShadedReliefImpl();
        shadedRelief.setBrightnessOnly(fieldConfigVisitor.getBoolean(FieldIdEnum.RASTER_SHADEDRELIEF_BRIGHTNESS));
        shadedRelief.setReliefFactor(fieldConfigVisitor.getExpression(FieldIdEnum.RASTER_SHADEDRELIEF_FACTOR));
    }
    Symbolizer symbolizer = null;
    StandardData standardData = getStandardData();
    Expression opacityExpression = fieldConfigVisitor.getExpression(FieldIdEnum.RASTER_OPACITY);
    // Geometry field
    Expression geometryField = ExtractGeometryField.getGeometryField(fieldConfigVisitor);
    RasterSymbolizer rasterSymbolizer = (RasterSymbolizer) getStyleFactory().rasterSymbolizer(standardData.name, geometryField, standardData.description, standardData.unit, opacityExpression, channelSelection, overlapBehavior, colorMap, contrastEnhancement, shadedRelief, symbolizer);
    if (vendorOptionRasterFactory != null) {
        vendorOptionRasterFactory.updateSymbol(rasterSymbolizer);
    }
    rasterSymbolizer.setOverlapBehavior(overlapBehavior);
    SelectedSymbol.getInstance().replaceSymbolizer(rasterSymbolizer);
    this.fireUpdateSymbol();
}
Also used : ColorMap(org.geotools.styling.ColorMap) ShadedRelief(org.geotools.styling.ShadedRelief) Symbolizer(org.geotools.styling.Symbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData) SelectedChannelType(org.geotools.styling.SelectedChannelType) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) OptionGroup(com.sldeditor.ui.detail.config.base.OptionGroup) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) Expression(org.opengis.filter.expression.Expression) ChannelSelection(org.geotools.styling.ChannelSelection) ShadedReliefImpl(org.geotools.styling.ShadedReliefImpl) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) OverlapBehavior(org.opengis.style.OverlapBehavior)

Example 59 with Symbolizer

use of org.geotools.styling.Symbolizer in project polymap4-core by Polymap4.

the class StyleCompositeSerializer method defaultFeatureTypeStyle.

protected FeatureTypeStyle defaultFeatureTypeStyle(org.geotools.styling.Style result, Style style, Symbolizer... symbolizers) {
    Rule rule = sf.createRule();
    // handle visibleIf
    FilterStyleProperty visibleIf = (FilterStyleProperty) style.visibleIf.get();
    if (visibleIf instanceof ScaleRangeFilter) {
        rule.setMinScaleDenominator(((ScaleRangeFilter) visibleIf).minScale.get());
        rule.setMaxScaleDenominator(((ScaleRangeFilter) visibleIf).maxScale.get());
    } else if (visibleIf instanceof ConstantFilter) {
        Filter filter = ((ConstantFilter) visibleIf).filter();
        if (!filter.equals(Filter.INCLUDE)) {
            rule.setFilter(filter);
        }
    } else {
        throw new RuntimeException("Unhandled Style.visibleIf type: " + visibleIf.getClass());
    }
    for (Symbolizer s : symbolizers) {
        rule.symbolizers().add(s);
    }
    ;
    FeatureTypeStyle fts = sf.createFeatureTypeStyle();
    fts.rules().add(rule);
    result.featureTypeStyles().add(fts);
    return fts;
}
Also used : ScaleRangeFilter(org.polymap.core.style.model.feature.ScaleRangeFilter) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) Filter(org.opengis.filter.Filter) FilterStyleProperty(org.polymap.core.style.model.feature.FilterStyleProperty) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) Symbolizer(org.geotools.styling.Symbolizer) ScaleRangeFilter(org.polymap.core.style.model.feature.ScaleRangeFilter)

Example 60 with Symbolizer

use of org.geotools.styling.Symbolizer in project hale by halestudio.

the class DefinitionImages method getLegendImage.

/**
 * Get a legend image for a given type definition
 *
 * @param type the type definition
 * @param dataSet the data set the type definition belongs to
 * @param definedOnly if only for defined styles a image shall be created
 * @return the legend image or <code>null</code>
 */
protected BufferedImage getLegendImage(TypeDefinition type, DataSet dataSet, boolean definedOnly) {
    StyleService ss = PlatformUI.getWorkbench().getService(StyleService.class);
    Style style = (definedOnly) ? (ss.getDefinedStyle(type)) : (ss.getStyle(type, dataSet));
    if (style == null) {
        return null;
    }
    // create a dummy feature based on the style
    Drawer d = Drawer.create();
    SimpleFeature feature = null;
    Symbolizer[] symbolizers = SLD.symbolizers(style);
    if (symbolizers.length > 0) {
        Symbolizer symbolizer = symbolizers[0];
        if (symbolizer instanceof LineSymbolizer) {
            feature = d.feature(d.line(LINE_POINTS));
        } else if (symbolizer instanceof PointSymbolizer) {
            feature = d.feature(d.point(WIDTH / 2, HEIGHT / 2));
        }
        if (symbolizer instanceof PolygonSymbolizer) {
            feature = d.feature(d.polygon(POLY_POINTS));
        }
    }
    if (feature != null) {
        BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
        // GraphicsEnvironment.getLocalGraphicsEnvironment().
        // getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(WIDTH, HEIGHT,
        // Transparency.TRANSLUCENT);
        // use white background to have a neutral color even if selected
        Color bg = Color.WHITE;
        Graphics2D g = image.createGraphics();
        try {
            g.setColor(bg);
            g.fillRect(0, 0, WIDTH, HEIGHT);
        } finally {
            g.dispose();
        }
        d.drawDirect(image, feature, style);
        return image;
    }
    return null;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) StyleService(eu.esdihumboldt.hale.ui.common.service.style.StyleService) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Color(java.awt.Color) Style(org.geotools.styling.Style) Drawer(org.geotools.map.legend.Drawer) SimpleFeature(org.opengis.feature.simple.SimpleFeature) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

Symbolizer (org.geotools.styling.Symbolizer)65 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)30 LineSymbolizer (org.geotools.styling.LineSymbolizer)29 PointSymbolizer (org.geotools.styling.PointSymbolizer)28 Rule (org.geotools.styling.Rule)22 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)20 Style (org.geotools.styling.Style)19 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)16 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)15 TextSymbolizer (org.geotools.styling.TextSymbolizer)15 StyledLayer (org.geotools.styling.StyledLayer)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 JsonObject (com.google.gson.JsonObject)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 NamedLayer (org.geotools.styling.NamedLayer)8 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)8 JsonElement (com.google.gson.JsonElement)7 Stroke (org.geotools.styling.Stroke)6 JsonArray (com.google.gson.JsonArray)5