[R-sig-Geo] RASTER library: one idea to merge several file in a loop

Robert J. Hijmans r.hijmans at gmail.com
Mon Dec 27 19:06:53 CET 2010


Gianni,

# make a list of file names, perhaps like this:
f <-list.files(pattern = ".asc")

# turn these into a list of RasterLayer objects
r <- lapply(f, raster)

# as you have the arguments as a list call 'merge' with 'do.call'
x <- do.call(merge, r)

Best, Robert

On Fri, Dec 24, 2010 at 7:23 AM, gianni lavaredo
<gianni.lavaredo at gmail.com> wrote:
> Dear Reserchers,
>
> MERRY CHRISTAMS
>
> I have several ASCII file and I wish to merge in a file with RASTER library
> "merge" function
>
> merge(x, y, ...)
>
>
> es: file1.asc, file2.asc, file3.asc, file4.asc, file5.asc
>
> my.list <-list("file1.asc", "file2.asc", "file3.asc", "file4.asc",
> "file5.asc")
>
>
> Dem.list <- list()
>
> for(m in 1:length(my.list)){
> dem <- raster(my.list[[m]])
> dem <- setMinMax(dem)
> Dem.list[[m]] <- dem
> }
>
> Now I have a list of DEM to merge with the function
>
> rm <- merge(Dem.list[[1]],Dem.list[[1]],Dem.list[[3]],Dem.list[[4]],Dem.list[[5]])
>
> I wish to use a loop with "merge" because I have more of 50 files and
> many areas to do this.
> Gianni
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list