Skip to content
Prev 28389 / 29559 Next

Execute Extract function on several Raster with points layer

Hello Ga?tan,

so as far as I understand, you have 3 main folders:
"Max_T", ? and ?
and in alll the three folders, there are subfolders
"1961", "1962", ... "1970"
In each folder, there are 366 raster files, for which the file naming 
conventions are not known by us, but some of the files are called
"max1961_1.asc", "max1961_2.asc", ... "max1961_366.asc" (in case of 
T_max and year 1961)

In this case, the 10980 layer that belongs to T_max can be read to one 
large RasterStack in this way:
tmax_filenames <- c(outer(X = as.character(1:366), Y = 
as.character(1961:1970), FUN = function(doy, year) paste0("N:/400074 
Conservation des sols et CC/Data/Climate data/Climate-10km/Max_T/", 
year, "/max", year, "_", doy, ".asc")))
tmax_raster <- stack(tmax_filenames)

You can give self-explanatory names to the raster layers:
names(tmax_raster) <- c(outer(X = as.character(1:366), Y = 
as.character(1961:1970), FUN = function(doy, year) paste0(year, "_", doy)))

But if the structure of the rasters are the same (i.e. the cell size, 
extent, projection), then I recommend you to do the raster-vector 
overlay once, save the cell numbers that you are interested in, and then 
in nested for loops (one loop for the climate variable, one for the year 
and one for the day) read the rasters one-by-one, extract the values 
according to the cell numbers, and save the result in a previously 
created data.frame. In this way, you may not encounter memory issues. 
Although, it will take a lot of time...

HTH,
?kos Bede-Fazekas
Hungarian Academy of Sciences

2020.09.17. 19:28 keltez?ssel, Gaetan Martinelli ?rta: