user1607
user1607

Reputation: 551

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?

Upvotes: 1

Views: 1323

Answers (1)

Robert Hijmans
Robert Hijmans

Reputation: 47051

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])
}

Upvotes: 3

Related Questions