I am trying to write a series of raster files into a new folder (after doing some image processing). However, when using my code, the files are but are not in the folder that I have created for that purpose.
I say they are but they are not because when I run my code and take a look inside the folder that I have created, a file pops-up, disappears, pops-up, disappears and this goes until I hit stop the R console.
Here is my code
Img.Raster <- list()
for (k in 1:length(list.pics)){
Img.Raster[[k]] <- raster(list.pics[k])
extent(Img.Raster[[k]])=c(coordinate.one.Image$CenterLeftx[[k]], coordinate.one.Image$CenterRightx[[k]],
coordinate.one.Image$CenterBottomy[[k]], coordinate.one.Image$CenterTopy[[k]])
proj4string(Img.Raster[[k]]) <- "+proj=utm +zone=15 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0"
writeRaster(Img.Raster[[k]],filename =paste0("/Users/Juan/Desktop/Images_Folder/"
, "Img_",names(list.pics[[k]])), format="GTiff",overwrite=TRUE)
}
list.Image
is a variable that contains 1745 images
Those anyone know what could be wrong?
Suggestion by @Jul
for (k in 1:length(list.pics)){
Img.Raster[[k]] <- raster(list.pics[k])
extent(Img.Raster[[k]])=c(coordinate.one.Image$CenterLeftx[[k]], coordinate.one.Image$CenterRightx[[k]],
coordinate.one.Image$CenterBottomy[[k]], coordinate.one.Image$CenterTopy[[k]])
proj4string(Img.Raster[[k]]) <- "+proj=utm +zone=15 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0"
writeRaster(Img.Raster[[k]],filename =paste0("/Users/Juan/Desktop/Images_Folder/"
, "Img_",stringr::str_pad(string = k,width = 4,side = "left",pad=0),
format="GTiff",overwrite=T)
}