Search in sources :

Example 1 with GridSampleDimension

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);
}
Also used : SelectedChannelType(org.geotools.styling.SelectedChannelType) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) ChannelSelection(org.geotools.styling.ChannelSelection) GridSampleDimension(org.geotools.coverage.GridSampleDimension)

Example 2 with GridSampleDimension

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;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StylePropertyFieldSite(org.polymap.core.style.ui.StylePropertyFieldSite) Arrays(java.util.Arrays) Combo(org.eclipse.swt.widgets.Combo) StylePropertyEditor(org.polymap.core.style.ui.StylePropertyEditor) RasterBand(org.polymap.core.style.model.raster.RasterBand) Collectors(java.util.stream.Collectors) IMessages(org.polymap.core.runtime.i18n.IMessages) Composite(org.eclipse.swt.widgets.Composite) SWT(org.eclipse.swt.SWT) ConstantRasterBand(org.polymap.core.style.model.raster.ConstantRasterBand) GridSampleDimension(org.geotools.coverage.GridSampleDimension) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Messages(org.polymap.core.style.Messages) Composite(org.eclipse.swt.widgets.Composite) GridSampleDimension(org.geotools.coverage.GridSampleDimension) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo)

Aggregations

GridSampleDimension (org.geotools.coverage.GridSampleDimension)2 Arrays (java.util.Arrays)1 Collectors (java.util.stream.Collectors)1 SWT (org.eclipse.swt.SWT)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 ChannelSelection (org.geotools.styling.ChannelSelection)1 ContrastEnhancement (org.geotools.styling.ContrastEnhancement)1 SelectedChannelType (org.geotools.styling.SelectedChannelType)1 IMessages (org.polymap.core.runtime.i18n.IMessages)1 Messages (org.polymap.core.style.Messages)1 ConstantRasterBand (org.polymap.core.style.model.raster.ConstantRasterBand)1 RasterBand (org.polymap.core.style.model.raster.RasterBand)1 StylePropertyEditor (org.polymap.core.style.ui.StylePropertyEditor)1 StylePropertyFieldSite (org.polymap.core.style.ui.StylePropertyFieldSite)1