use of org.geotools.styling.ContrastEnhancement in project sldeditor by robward-scisys.
the class VOGeoServerContrastEnhancementNormalizeBlueTest method createChannelSelection.
/**
* Creates the channel selection object.
*
* @param styleFactory the style factory
* @param contrastMethod the contrast method
* @return the channel selection
*/
private ChannelSelection createChannelSelection(StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Map<String, Expression> options = contrastEnhancement.getOptions();
options.put("algorithm", ff.literal("StretchToMinimumMaximum"));
options.put("minValue", ff.literal("1"));
options.put("maxValue", ff.literal("5"));
SelectedChannelType channelType = styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
SelectedChannelType[] channels = new SelectedChannelType[3];
channels[0] = channelType;
channels[1] = channelType;
channels[2] = channelType;
ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
return channelSelection;
}
use of org.geotools.styling.ContrastEnhancement in project sldeditor by robward-scisys.
the class RasterSymbolizerDetailsTest method testRasterSymbolizerDetailsColourChannel.
/**
* 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 testRasterSymbolizerDetailsColourChannel() {
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);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(ff.literal(.5), "ramp");
SelectedChannelType redChannel = styleFactory.createSelectedChannelType("red", contrastEnhancement);
SelectedChannelType greenChannel = styleFactory.createSelectedChannelType("green", contrastEnhancement);
SelectedChannelType blueChannel = styleFactory.createSelectedChannelType("blue", contrastEnhancement);
SelectedChannelType[] channels = new SelectedChannelType[3];
channels[0] = redChannel;
channels[1] = greenChannel;
channels[2] = blueChannel;
RasterSymbolizer symbolizer = DefaultSymbols.createDefaultRasterSymbolizer();
symbolizer.setChannelSelection(styleFactory.createChannelSelection(channels));
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();
}
use of org.geotools.styling.ContrastEnhancement in project sldeditor by robward-scisys.
the class VOGeoServerContrastEnhancementNormalizeGreyTest method createChannelSelection.
/**
* Creates the channel selection object.
*
* @param styleFactory the style factory
* @param contrastMethod the contrast method
* @return the channel selection
*/
private ChannelSelection createChannelSelection(StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Map<String, Expression> options = contrastEnhancement.getOptions();
options.put("algorithm", ff.literal("StretchToMinimumMaximum"));
options.put("minValue", ff.literal("1"));
options.put("maxValue", ff.literal("5"));
SelectedChannelType channelType = styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
SelectedChannelType[] channels = new SelectedChannelType[3];
channels[0] = channelType;
channels[1] = channelType;
channels[2] = channelType;
ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
return channelSelection;
}
use of org.geotools.styling.ContrastEnhancement in project sldeditor by robward-scisys.
the class VOGeoServerContrastEnhancementNormalizeRedTest method createChannelSelectionError.
/**
* Creates the channel selection error object.
*
* @param styleFactory the style factory
* @param contrastMethod the contrast method
* @return the channel selection
*/
private ChannelSelection createChannelSelectionError(StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Map<String, Expression> options = contrastEnhancement.getOptions();
options.put("algorithm", ff.literal("TestStretchToMinimumMaximum"));
options.put("minValue", ff.literal("1.0"));
options.put("maxValue", ff.literal("5.0"));
SelectedChannelType channelType = styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
SelectedChannelType[] channels = new SelectedChannelType[3];
channels[0] = channelType;
channels[1] = channelType;
channels[2] = channelType;
ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
return channelSelection;
}
use of org.geotools.styling.ContrastEnhancement in project sldeditor by robward-scisys.
the class RasterReader method createRGBChannelSymbol.
/**
* Creates the RGB channel symbol.
*
* @param sym the sym
* @param cov the cov
* @param numBands the num bands
*/
private void createRGBChannelSymbol(RasterSymbolizer sym, GridCoverage2D cov, int numBands) {
// Get the names of the bands
String[] sampleDimensionNames = new String[numBands];
for (int i = 0; i < numBands; i++) {
GridSampleDimension dim = cov.getSampleDimension(i);
sampleDimensionNames[i] = dim.getDescription().toString();
}
final int RED = 0;
final int GREEN = 1;
final int BLUE = 2;
int[] channelNum = { -1, -1, -1 };
// Note that the channel numbers we record are indexed from 1, not 0.
for (int i = 0; i < numBands; i++) {
String name = sampleDimensionNames[i].toLowerCase();
if (name != null) {
if (name.matches("red.*")) {
channelNum[RED] = i + 1;
} else if (name.matches("green.*")) {
channelNum[GREEN] = i + 1;
} else if (name.matches("blue.*")) {
channelNum[BLUE] = i + 1;
}
}
}
// we fall back to using the first three bands in order
if (channelNum[RED] < 0 || channelNum[GREEN] < 0 || channelNum[BLUE] < 0) {
channelNum[RED] = 1;
channelNum[GREEN] = 2;
channelNum[BLUE] = 3;
}
// Now we create a RasterSymbolizer using the selected channels
SelectedChannelType[] sct = new SelectedChannelType[cov.getNumSampleDimensions()];
ContrastEnhancement ce = sf.contrastEnhancement(ff.literal(1.0), ContrastMethod.NORMALIZE);
for (int i = 0; i < 3; i++) {
sct[i] = sf.createSelectedChannelType(String.valueOf(channelNum[i]), ce);
}
ChannelSelection sel = sf.channelSelection(sct[RED], sct[GREEN], sct[BLUE]);
sym.setChannelSelection(sel);
}
Aggregations