public static GridCoverage2D createCoverageFromTemplate( GridCoverage2D template, Double value,
            WritableRaster[] writableRasterHolder ) {
        RegionMap regionMap = getRegionParamsFromGridCoverage(template);

        double west = regionMap.getWest();
        double south = regionMap.getSouth();
        double east = regionMap.getEast();
        double north = regionMap.getNorth();
        int cols = regionMap.getCols();
        int rows = regionMap.getRows();
        ComponentSampleModel sampleModel = new ComponentSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, 1, cols, new int[]{0});

        WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null);
        if (value != null) {
            // autobox only once
            double v = value;
            for( int y = 0; y < rows; y++ ) {
                for( int x = 0; x < cols; x++ ) {
                    raster.setSample(x, y, 0, v);
                }
            }
        }
        if (writableRasterHolder != null) {
            writableRasterHolder[0] = raster;
        }

        Envelope2D writeEnvelope = new Envelope2D(template.getCoordinateReferenceSystem(), west, south, east - west,
                north - south);
        GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);
        GridCoverage2D coverage2D = factory.create("newraster", raster, writeEnvelope);
        return coverage2D;
    }
public static GridCoverage2D createCoverageFromTemplate ( GridCoverage2D template , Double value , WritableRaster [ ] writableRasterHolder ) { RegionMap regionMap = getRegionParamsFromGridCoverage ( template ) ; double west = regionMap . getWest ( ) ; double south = regionMap . getSouth ( ) ; double east = regionMap . getEast ( ) ; double north = regionMap . getNorth ( ) ; int cols = regionMap . getCols ( ) ; int rows = regionMap . getRows ( ) ; ComponentSampleModel sampleModel = new ComponentSampleModel ( DataBuffer . TYPE_DOUBLE , cols , rows , 1 , cols , new int [ ] { 0 } ) ; WritableRaster raster = RasterFactory . createWritableRaster ( sampleModel , null ) ; if ( value != null ) { double v = value ; for ( int y = 0 ; y < rows ; y ++ ) { for ( int x = 0 ; x < cols ; x ++ ) { raster . setSample ( x , y , 0 , v ) ; } } } if ( writableRasterHolder != null ) { writableRasterHolder [ 0 ] = raster ; } Envelope2D writeEnvelope = new Envelope2D ( template . getCoordinateReferenceSystem ( ) , west , south , east - west , north - south ) ; GridCoverageFactory factory = CoverageFactoryFinder . getGridCoverageFactory ( null ) ; GridCoverage2D coverage2D = factory . create ( "newraster" , raster , writeEnvelope ) ; return coverage2D ; }
Creates a new {@link GridCoverage2D} using an existing as template.

@param template the template to use.
@param value the value to set the new raster to, if not <code>null</code>.
@param writableRasterHolder an array of length 1 to place the writable raster in, that
was can be used to populate the coverage. If <code>null</code>, it is ignored.
@return the new coverage.