// OUTPUT
//
// /////////////////////////////////////////////////////////////////////
final int numSourceBands=source.getNumSampleDimensions();
final int numActualBands= finalImage.getSampleModel().getNumBands();
final GridCoverageFactory factory = getCoverageFactory();
final HashMap<Object,Object> props = new HashMap<Object,Object>();
if(source.getProperties() != null) {
props.putAll(source.getProperties());
}
if(numActualBands==numSourceBands) {
final String name = "ce_coverage" + source.getName();
output = factory.create(
name,
finalImage,
(GridGeometry2D)source.getGridGeometry(),
source.getSampleDimensions(),
new GridCoverage[]{source},
props);
} else {
// replicate input bands
final GridSampleDimension sd[]= new GridSampleDimension[numActualBands];
for(int i=0;i<numActualBands;i++)
sd[i]=(GridSampleDimension) source.getSampleDimension(0);
output = factory.create(
"ce_coverage"+source.getName().toString(),
finalImage,
(GridGeometry2D)source.getGridGeometry(),
sd,
new GridCoverage[]{source},