Search in sources :

Example 26 with RasterSymbolizer

use of org.geotools.styling.RasterSymbolizer 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 27 with RasterSymbolizer

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

the class RasterSymbolizerDetails method populate.

/**
 * Populate.
 *
 * @param selectedSymbol the selected symbol
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.selectedsymbol.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    if (selectedSymbol != null) {
        RasterSymbolizer rasterSymbolizer = (RasterSymbolizer) selectedSymbol.getSymbolizer();
        if (rasterSymbolizer != null) {
            populateStandardData(rasterSymbolizer);
            // Opacity
            fieldConfigVisitor.populateField(FieldIdEnum.RASTER_OPACITY, rasterSymbolizer.getOpacity());
            // Contrast enhancement
            ContrastEnhancement contrast = rasterSymbolizer.getContrastEnhancement();
            GroupConfigInterface group = getGroup(GroupIdEnum.RASTER_CONTRAST);
            if (group != null) {
                group.enable(contrast != null);
            }
            if (contrast != null) {
                Expression gammaValue = contrast.getGammaValue();
                fieldConfigVisitor.populateField(FieldIdEnum.RASTER_CONTRAST_GAMMAVALUE, gammaValue);
                populateContrastMethod(contrast, GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD);
            }
            // Channel selection
            group = getGroup(GroupIdEnum.RASTER_CHANNELSELECTION);
            if (group != null) {
                MultiOptionGroup channelSelectionGroup = (MultiOptionGroup) group;
                ChannelSelection channelSelection = rasterSymbolizer.getChannelSelection();
                boolean enableChannelSelection = false;
                if (channelSelection != null) {
                    SelectedChannelType[] rgbChannels = channelSelection.getRGBChannels();
                    enableChannelSelection = ((channelSelection.getGrayChannel() != null) || (rgbChannels[0] != null) || (rgbChannels[1] != null) || (rgbChannels[2] != null));
                }
                channelSelectionGroup.enable(enableChannelSelection);
                if (enableChannelSelection) {
                    SelectedChannelType greyChannel = channelSelection.getGrayChannel();
                    if (greyChannel != null) {
                        channelSelectionGroup.setOption(GroupIdEnum.RASTER_GREY_CHANNEL_OPTION);
                        populateContrastEnhancementGroup(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, greyChannel);
                    } else {
                        SelectedChannelType[] rgbChannels = channelSelection.getRGBChannels();
                        channelSelectionGroup.setOption(GroupIdEnum.RASTER_RGB_CHANNEL_OPTION);
                        populateContrastEnhancementGroup(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, rgbChannels[0]);
                        populateContrastEnhancementGroup(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, rgbChannels[1]);
                        populateContrastEnhancementGroup(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, rgbChannels[2]);
                    }
                }
            }
            // Colour map
            ColorMap colourMap = rasterSymbolizer.getColorMap();
            fieldConfigVisitor.populateComboBoxField(FieldIdEnum.RASTER_COLOURMAP_TYPE, Integer.valueOf(colourMap.getType()).toString());
            fieldConfigVisitor.populateColourMapField(FieldIdEnum.RASTER_COLOURMAP, colourMap);
            // Shaded relief
            ShadedRelief shadedRelief = rasterSymbolizer.getShadedRelief();
            group = getGroup(GroupIdEnum.RASTER_SHADEDRELIEF);
            if (group != null) {
                group.enable(shadedRelief != null);
            }
            if (shadedRelief != null) {
                fieldConfigVisitor.populateBooleanField(FieldIdEnum.RASTER_SHADEDRELIEF_BRIGHTNESS, shadedRelief.isBrightnessOnly());
                fieldConfigVisitor.populateField(FieldIdEnum.RASTER_SHADEDRELIEF_FACTOR, shadedRelief.getReliefFactor());
            }
            // Overlap behaviour
            OverlapBehavior overlapBehaviour = rasterSymbolizer.getOverlapBehavior();
            group = getGroup(GroupIdEnum.RASTER_OVERLAP);
            if (group != null) {
                group.enable(overlapBehaviour != null);
            }
            if (overlapBehaviour != null) {
                fieldConfigVisitor.populateComboBoxField(FieldIdEnum.RASTER_OVERLAP_BEHAVIOUR, overlapBehaviour.name());
            }
            if (vendorOptionRasterFactory != null) {
                vendorOptionRasterFactory.populate(rasterSymbolizer);
            }
        }
    }
}
Also used : RasterSymbolizer(org.geotools.styling.RasterSymbolizer) SelectedChannelType(org.geotools.styling.SelectedChannelType) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) Expression(org.opengis.filter.expression.Expression) ChannelSelection(org.geotools.styling.ChannelSelection) ColorMap(org.geotools.styling.ColorMap) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) ShadedRelief(org.geotools.styling.ShadedRelief) OverlapBehavior(org.opengis.style.OverlapBehavior)

Example 28 with RasterSymbolizer

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

the class CreateInternalDataSourceTest method testDetermineGeometryType.

/**
 * Test method for
 * {@link com.sldeditor.datasource.impl.CreateInternalDataSource#determineGeometryType(StyledLayerDescriptor)}.
 */
@Test
public void testDetermineGeometryType() {
    TestCreateInternalDataSource ds = new TestCreateInternalDataSource();
    assertEquals(GeometryTypeEnum.UNKNOWN, ds.callDetermineGeometryType(null));
    // Create StyledLayerDescriptor
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    sld.addStyledLayer(namedLayer);
    UserLayer userLayer = styleFactory.createUserLayer();
    sld.addStyledLayer(userLayer);
    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);
    // Raster
    RasterSymbolizer raster = DefaultSymbols.createDefaultRasterSymbolizer();
    rule.symbolizers().add(raster);
    assertEquals(GeometryTypeEnum.RASTER, ds.callDetermineGeometryType(sld));
    // Polygon
    rule.symbolizers().clear();
    PolygonSymbolizer polygon = DefaultSymbols.createDefaultPolygonSymbolizer();
    rule.symbolizers().add(polygon);
    assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
    // Line
    rule.symbolizers().clear();
    LineSymbolizer line = DefaultSymbols.createDefaultLineSymbolizer();
    rule.symbolizers().add(line);
    assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
    // Point
    rule.symbolizers().clear();
    PointSymbolizer point = DefaultSymbols.createDefaultPointSymbolizer();
    rule.symbolizers().add(point);
    assertEquals(GeometryTypeEnum.POINT, ds.callDetermineGeometryType(sld));
    // Add line to point
    rule.symbolizers().add(line);
    assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
    // Add point, line
    rule.symbolizers().clear();
    rule.symbolizers().add(line);
    rule.symbolizers().add(point);
    assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
    // Add polygon, line
    rule.symbolizers().clear();
    rule.symbolizers().add(point);
    rule.symbolizers().add(polygon);
    assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) LineSymbolizer(org.geotools.styling.LineSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) UserLayer(org.geotools.styling.UserLayer) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 29 with RasterSymbolizer

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

the class RasterSymbolizerDetailsTest method testRasterSymbolizerDetailsGreyChannel.

/**
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#RasterSymbolizerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#isDataPresent()}.
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#getFieldDataManager()}.
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#preLoadSymbol()}.
 */
@Test
public void testRasterSymbolizerDetailsGreyChannel() {
    RasterSymbolizerDetails panel = new RasterSymbolizerDetails();
    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 expectedRuleValue = "rule test value";
    rule.setName(expectedRuleValue);
    RasterSymbolizer symbolizer = DefaultSymbols.createDefaultRasterSymbolizer();
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(ff.literal(.5), "ramp");
    SelectedChannelType greyChannel = styleFactory.createSelectedChannelType("grey", contrastEnhancement);
    symbolizer.setChannelSelection(styleFactory.channelSelection(greyChannel));
    String expectedNameValue = "symbolizer test value";
    symbolizer.setName(expectedNameValue);
    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);
    panel.dataChanged(null);
    FieldConfigString nameField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.NAME);
    assertNull(nameField);
    assertTrue(panel.isDataPresent());
    // Reset to default value
    panel.preLoadSymbol();
}
Also used : FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) RasterSymbolizerDetails(com.sldeditor.ui.detail.RasterSymbolizerDetails) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FilterFactory(org.opengis.filter.FilterFactory) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) SelectedChannelType(org.geotools.styling.SelectedChannelType) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) 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) Test(org.junit.Test)

Aggregations

RasterSymbolizer (org.geotools.styling.RasterSymbolizer)29 Test (org.junit.Test)12 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)10 Rule (org.geotools.styling.Rule)10 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)10 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)9 Style (org.geotools.styling.Style)9 RasterSymbolizerDetails (com.sldeditor.ui.detail.RasterSymbolizerDetails)7 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)7 MultiOptionGroup (com.sldeditor.ui.detail.config.base.MultiOptionGroup)7 ChannelSelection (org.geotools.styling.ChannelSelection)7 LineSymbolizer (org.geotools.styling.LineSymbolizer)7 PointSymbolizer (org.geotools.styling.PointSymbolizer)7 NamedLayer (org.geotools.styling.NamedLayer)6 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)6 Symbolizer (org.geotools.styling.Symbolizer)6 Box (javax.swing.Box)5 FilterFactory (org.opengis.filter.FilterFactory)5 MalformedURLException (java.net.MalformedURLException)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4