Can somebody help me on how to copy multiple filenames in a single CSV file? I have 365 raster files and a polygon dataset with 5 features. What I am trying to do is extract cell values corresponding to polygon features. I am able to do this but not able to copy the corresponding raster filenames in a single CSV. Below is my code:
library(rgdal)
library(raster)
setwd("C:/PHP_Win7/Etios/2007")
polygong <- readOGR("C:/PHP_Win7/Etios/2007", "Ethn")
rasterfiles <- list.files(".", pattern = "tif")
for (j in 1:length(rasterfiles)) {
curRaster <- raster(paste("C:/PHP_Win7/Etios/2007", rasterfiles[j], sep = "/"))
csvDatatoWrite <- data.frame(coordinates(polygong),
polygong$Name,
extract(curRaster, polygong))
write.table(csvDatatoWrite, file = "output.csv",
append = TRUE, sep = ",", row.names = F)
}
The output I am getting is
I would like to replace "extract.curRaster..polygong." column heading in output sample with corresponding filenames. Any help on this?