public static GridCoverage2D mergeCoverages ( GridCoverage2D valuesMap , GridCoverage2D onMap ) { RegionMap valuesRegionMap = getRegionParamsFromGridCoverage ( valuesMap ) ; int cs = valuesRegionMap . getCols ( ) ; int rs = valuesRegionMap . getRows ( ) ; RegionMap onRegionMap = getRegionParamsFromGridCoverage ( onMap ) ; int tmpcs = onRegionMap . getCols ( ) ; int tmprs = onRegionMap . getRows ( ) ; if ( cs != tmpcs || rs != tmprs ) { throw new IllegalArgumentException ( "The raster maps have to be of equal size to be mapped." ) ; } RandomIter valuesIter = RandomIterFactory . create ( valuesMap . getRenderedImage ( ) , null ) ; WritableRaster outWR = renderedImage2WritableRaster ( onMap . getRenderedImage ( ) , false ) ; WritableRandomIter outIter = RandomIterFactory . createWritable ( outWR , null ) ; for ( int c = 0 ; c < cs ; c ++ ) { for ( int r = 0 ; r < rs ; r ++ ) { double value = valuesIter . getSampleDouble ( c , r , 0 ) ; if ( ! isNovalue ( value ) ) outIter . setSample ( c , r , 0 , value ) ; } } GridCoverage2D outCoverage = buildCoverage ( "merged" , outWR , onRegionMap , valuesMap . getCoordinateReferenceSystem ( ) ) ; //$NON-NLS-1$ return outCoverage ; }
Coverage merger .