Search code examples
rasciirastertiffterra

Batch process multiple ASCII to Raster files in R


I am trying to convert some ASCII test files into .tif files, so i can use the .tif files in bnspatial.

Any suggestions? Is there a package out there that does this or do i need to link R with a GIS software?


Solution

  • You can do something along these lines:

    library(terra)
    fasc <- list.files(pattern='\\.asc$', full=TRUE)
    ftif <- gsub("\\.asc$", ".tif", fasc)
    
    for (i in 1:length(fasc)) {
        r <- rast(fasc[i])
        r <- writeRaster(r, ftif[i])
    }