use of org.geotools.coverage.GridSampleDimension 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);
}
use of org.geotools.coverage.GridSampleDimension in project polymap4-core by Polymap4.
the class ConstantRasterBandEditor method createContents.
@Override
public Composite createContents(Composite parent) {
Composite contents = super.createContents(parent);
Combo combo = new Combo(contents, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
GridSampleDimension[] bands = site().gridCoverage.get().getSampleDimensions();
combo.setItems(Arrays.stream(bands).map(band -> band.getDescription().toString()).collect(Collectors.toList()).toArray(new String[0]));
combo.select(prop.get().band.get());
combo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
prop.get().band.set(combo.getSelectionIndex());
}
});
return contents;
}
Aggregations