Java Code Examples for org.geotools.coverage.grid.GridCoverage2D#getNumSampleDimensions()

The following examples show how to use org.geotools.coverage.grid.GridCoverage2D#getNumSampleDimensions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RasterReader.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the rgb style.
 *
 * @param reader the reader
 * @param raster the raster
 * @return the style
 */
private Style createRGBStyle(AbstractGridCoverage2DReader reader, WritableRaster raster) {
    RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();

    GridCoverage2D cov = null;
    try {
        cov = reader.read(null);
    } catch (IOException giveUp) {
        throw new RuntimeException(giveUp);
    }
    // We need at least three bands to create an RGB style
    int numBands = cov.getNumSampleDimensions();
    if (numBands < 3) {
        createRGBImageSymbol(sym, cov, raster);
    } else {
        createRGBChannelSymbol(sym, cov, numBands);
    }
    return SLD.wrapSymbolizers(sym);
}
 
Example 2
Source File: RasterDataAdapter.java    From geowave with Apache License 2.0 6 votes vote down vote up
public RasterDataAdapter(
    final String coverageName,
    final Map<String, String> metadata,
    final GridCoverage2D originalGridCoverage,
    final int tileSize,
    final boolean buildPyramid) {
  this(
      coverageName,
      metadata,
      originalGridCoverage,
      tileSize,
      buildPyramid,
      DEFAULT_BUILD_HISTOGRAM,
      new double[originalGridCoverage.getNumSampleDimensions()][],
      new NoDataMergeStrategy());
}
 
Example 3
Source File: RasterDataAdapter.java    From geowave with Apache License 2.0 5 votes vote down vote up
public RasterDataAdapter(
    final String coverageName,
    final Map<String, String> metadata,
    final GridCoverage2D originalGridCoverage) {
  this(
      coverageName,
      metadata,
      originalGridCoverage,
      DEFAULT_TILE_SIZE,
      DEFAULT_BUILD_PYRAMID,
      DEFAULT_BUILD_HISTOGRAM,
      new double[originalGridCoverage.getNumSampleDimensions()][],
      new NoDataMergeStrategy());
}
 
Example 4
Source File: RasterReader.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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};
    // We examine the band names looking for "red...", "green...", "blue...".
    // 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;
            }
        }
    }
    // If we didn't find named bands "red...", "green...", "blue..."
    // 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);
}
 
Example 5
Source File: RasterDataAdapter.java    From geowave with Apache License 2.0 4 votes vote down vote up
public RasterDataAdapter(
    final String coverageName,
    final Map<String, String> metadata,
    final GridCoverage2D originalGridCoverage,
    final int tileSize,
    final boolean buildPyramid,
    final boolean buildHistogram,
    final double[][] noDataValuesPerBand,
    final RasterTileMergeStrategy<?> mergeStrategy) {
  staticInit();

  final RenderedImage img = originalGridCoverage.getRenderedImage();
  final SampleModel imgSampleModel = img.getSampleModel();
  if ((imgSampleModel.getWidth() != tileSize) || (imgSampleModel.getHeight() != tileSize)) {
    sampleModel = imgSampleModel.createCompatibleSampleModel(tileSize, tileSize);
  } else {
    sampleModel = imgSampleModel;
  }
  colorModel = img.getColorModel();
  this.metadata = metadata;
  this.coverageName = coverageName;
  this.tileSize = tileSize;
  if (buildHistogram) {
    histogramConfig = new HistogramConfig(sampleModel);
  } else {
    histogramConfig = null;
  }
  if ((noDataValuesPerBand != null) && (noDataValuesPerBand.length != 0)) {
    this.noDataValuesPerBand = noDataValuesPerBand;
    backgroundValuesPerBand = new double[noDataValuesPerBand.length];
    for (int d = 0; d < this.noDataValuesPerBand.length; d++) {
      if ((noDataValuesPerBand[d] != null) && (noDataValuesPerBand[d].length > 0)) {
        backgroundValuesPerBand[d] = noDataValuesPerBand[d][0];
      } else {
        backgroundValuesPerBand[d] = 0.0;
      }
    }
  } else {
    this.noDataValuesPerBand = new double[originalGridCoverage.getNumSampleDimensions()][];
    for (int d = 0; d < this.noDataValuesPerBand.length; d++) {
      this.noDataValuesPerBand[d] = originalGridCoverage.getSampleDimension(d).getNoDataValues();
    }
    backgroundValuesPerBand = CoverageUtilities.getBackgroundValues(originalGridCoverage);
  }

  this.buildPyramid = buildPyramid;
  this.mergeStrategy = mergeStrategy;
  init();
}