final String grassParam = ArcGridFormat.GRASS.getName().getCode().toString();
final String cellSizeParam = ArcGridFormat.FORCE_CELLSIZE
.getName().getCode().toString();
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
Parameter param = (Parameter) parameters[i];
String name = param.getDescriptor().getName().toString();
if (param.getDescriptor().getName().getCode().equals(
AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName()
.toString())) {
gtParams = (GeoToolsWriteParams) param.getValue();
}
if (name.equalsIgnoreCase(grassParam))
grass = param.booleanValue();
if (name.equalsIgnoreCase(cellSizeParam))
forceCellSize = param.booleanValue();
}
}
if (gtParams == null)
gtParams = new ArcGridWriteParams();
// write band
int[] writeBands = gtParams.getSourceBands();
writeBand = CoverageUtilities.getVisibleBand(gc.getRenderedImage());
if ((writeBands == null || writeBands.length == 0 || writeBands.length > 1)
&& (writeBand < 0 || writeBand > gc
.getNumSampleDimensions()))
throw new IllegalArgumentException(
"You need to supply a valid index for deciding which band to write.");
if (!((writeBands == null || writeBands.length == 0 || writeBands.length > 1)))
writeBand = writeBands[0];
// /////////////////////////////////////////////////////////////////
//
// Getting CRS and envelope information
//
// /////////////////////////////////////////////////////////////////
final CoordinateReferenceSystem crs = gc.getCoordinateReferenceSystem2D();
// /////////////////////////////////////////////////////////////////
//
// getting visible band, if needed
// /////////////////////////////////////////////////////////////////
final int numBands = gc.getNumSampleDimensions();
if (numBands > 1) {
final int visibleBand;
if (writeBand > 0 && writeBand < numBands)
visibleBand = writeBand;
else
visibleBand = CoverageUtilities.getVisibleBand(gc);
final ParameterValueGroup param = (ParameterValueGroup) ArcGridWriter.bandSelectParams
.clone();
param.parameter("source").setValue(gc);
param.parameter("SampleDimensions").setValue(
new int[] { visibleBand });
gc = (GridCoverage2D) bandSelectFactory
.doOperation(param, null);
}
// /////////////////////////////////////////////////////////////////