GeneralEnvelope envelope = reader.getOriginalEnvelope();
cinfo.setNativeBoundingBox( new ReferencedEnvelope( envelope ) );
cinfo.setLatLonBoundingBox( new ReferencedEnvelope(CoverageStoreUtils.getWGS84LonLatEnvelope(envelope)) );
GridEnvelope originalRange=reader.getOriginalGridRange();
cinfo.setGrid(new GridGeometry2D(originalRange,reader.getOriginalGridToWorld(PixelInCell.CELL_CENTER),nativeCRS));
///////////////////////////////////////////////////////////////////////
//
// Now reading a fake small GridCoverage just to retrieve meta
// information about bands:
//
// - calculating a new envelope which is 1/20 of the original one
// - reading the GridCoverage subset
//
///////////////////////////////////////////////////////////////////////
Format format = csinfo.getFormat();
final GridCoverage2D gc;
final ParameterValueGroup readParams = format.getReadParameters();
final Map parameters = CoverageUtils.getParametersKVP(readParams);
final int minX=originalRange.getLow(0);
final int minY=originalRange.getLow(1);
final int width=originalRange.getSpan(0);
final int height=originalRange.getSpan(1);
final int maxX=minX+(width<=5?width:5);
final int maxY=minY+(height<=5?height:5);
//we have to be sure that we are working against a valid grid range.
final GridEnvelope2D testRange= new GridEnvelope2D(minX,minY,maxX,maxY);