<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Hello everyone, R team, <br/>
<br/>
Sorry in advance for this long message. Your help will be invaluable.<br/>
<br/>
For a few days now i have been blocked to execute a task on R. I will try to synthesize my problem.<br/>
<br/>
I have several raster. I have an ASCII file for each day of a year with a single band. For 30 years, and for three climatic variables on grid 10km/10km (T_min, T_max, Precipitation). So i have a total around of 32 940 raster files (366days*30years*3variables).<br/>
<br/>
Also, i have a layer of aroud 1000 points.</div>
<div><br/>
I tried to use the Stack function and then make the intersection for each raster files with my 1000 points.</div>
<div>I cannot create an independent matrix for all my files where i applied the "extract" function, to then concatenate all my matrices in order to have a single table.</div>
<div> </div>
<div><br/>
I tried this, exemple for 10 years et only T_Max (my files are organized the same for my two other variables) :</div>
<div> </div>
<div><strong>#Datapoints</strong></div>
<div> </div>
<div>
<div>
<div>Datapoints<-readOGR(dsn="H:/Inventaire/R/final",<br/>
layer="Centroid_champs")</div>
<div> </div>
<div>Datapoints<- spTransform (Datapoints, CRS ("+init=epsg:4326") ) # 1022 points in the data</div>
<div>st_crs(Datapoints)</div>
</div>
<div> </div>
<div> </div>
<div><strong>#Rasters files</strong></div>
<div> </div>
<div>folders = list(<br/>
file.path('N:','Data','Climate data','Climate-10km','Max_T','1961'), #Each year includes daily data, the names of my several raster is "max1961_1", "max1961_10", "max1961_100", etc...<br/>
file.path('N:','Data','Climate data','Climate-10km','Max_T','1962'),<br/>
file.path('N:','Data','Climate data','Climate-10km','Max_T','1963'),<br/>
file.path('N:','Data','Climate data','Climate-10km','Max_T','1964'),<br/>
file.path('N:','Data','Climate data','Climate-10km','Max_T','1965'),<br/>
file.path('N:','Data','Climate data','Climate-10km','Max_T','1966'),<br/>
file.path('N:','Data','Climate data','Climate-10km','Max_T','1967'),<br/>
file.path('N:','Data','Climate data','Climate-10km','Max_T','1968'),<br/>
file.path('N:','Data','Climate data','Climate-10km','Max_T','1969'),<br/>
file.path('N:','Data','Climate data','Climate-10km','Max_T','1970')</div>
<div>)<br/>
</div>
<div>files = unlist(sapply(folders, function(folder) {<br/>
list.files(folder, full.names=TRUE)<br/>
}))<br/>
files</div>
<div><br/>
MET <- lapply(files, raster)</div>
<div>
<div>s <- raster::stack(MET)<br/>
<br/>
output <- list()<br/>
for(i in 1:length(MET)){<br/>
output[[i]] <- extract(s, Datapoints)<br/>
names(output)[[i]] <- paste("Année", MET[i], sep = "_")<br/>
}</div>
<div> </div>
<div> </div>
<div> </div>
<div>Also, i tried that : <br/>
</div>
<div>
<div>p1 <- 1022 (ID of my DataPoints) ; p2 <- 1 (column where there are the values extracted from my raster) ; p3 <- 3660 # 3660matrix (366 day* 10 years)<br/>
matlist <- list(array(NA,c(p1,p2,p3))) # doing a list of independant matrix</div>
<div><br/>
for(i in seq_along(MET)){<br/>
<br/>
matlist[[i]] <- extract(s, Datapoints)<br/>
}</div>
</div>
<div> </div>
<div> </div>
<div> </div>
<div>But, nothing works...<br/>
I would like my script to perform these actions :</div>
<div> </div>
<div>- For each Raster in my Rasterstack, extract the climatic data values and link them to my "Datapoints",</div>
<div>- Take the name of my file, take the first three characters of the name to get a column of my weather variable, here, "T_Max" (column with my raster values) ; Take the following four characters then report this information in a new column "Year", and finally, take the last characters of the file name to create a new column "Day".<br/>
- Concatenate all the independent output matrices corresponding to each intersection made with my different raster files
<div> </div>
<div> </div>
<div>In the end, I would have a huge table, but one that will allow me to do my analysis : </div>
<div> </div>
<div>
<div>Table with 9 attributes (6 attributs of my points + Year + Day + T_Max) like this :</div>
<div> </div>
<div>
<div> </div>
<div>
<table width="320">
<colgroup>
<col span="4" width="80"/>
</colgroup>
<tbody>
<tr height="20">
<td height="20" width="80">ID Datapoint</td>
<td width="80">Year</td>
<td width="80">Day</td>
<td width="80">T_Max</td>
</tr>
<tr height="20">
<td height="20">1</td>
<td>1960</td>
<td>1</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">2</td>
<td>1960</td>
<td>1</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">…...</td>
<td>1960</td>
<td>1</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">1022</td>
<td>1960</td>
<td>1</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">1</td>
<td>1960</td>
<td>2</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">2</td>
<td>1960</td>
<td>2</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">…...</td>
<td>1960</td>
<td>2</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">1022</td>
<td>1960</td>
<td>2</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">…..</td>
<td>…..</td>
<td>…..</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">1</td>
<td>1970</td>
<td>1</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">2</td>
<td>1970</td>
<td>1</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">…...</td>
<td>1970</td>
<td>1</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">1022</td>
<td>1970</td>
<td>1</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">1</td>
<td>1970</td>
<td>2</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">2</td>
<td>1970</td>
<td>2</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">…...</td>
<td>1970</td>
<td>2</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">1022</td>
<td>1970</td>
<td>2</td>
<td> </td>
</tr>
<tr height="20">
<td height="20">…..</td>
<td>…..</td>
<td>…..</td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div> </div>
</div>
<div> </div>
</div>
</div>
<div>Could a loop do this task ?<br/>
<br/>
I'm sorry, i am gradually learning to manipulate R, but this exercise is more difficult than expected...Please feel free to tell me if my question is inappropriate.</div>
<div> </div>
<div><br/>
Thank you very much in advance for your answers. Your help or your comments will be really appreciated.<br/>
<br/>
Have a good day.</div>
<div> </div>
<div><br/>
Gaëtan Martinelli<br/>
Water and Agriculture research professional in Quebec.</div>
<div> </div>
<div> </div>
<div> </div>
</div>
</div></div></body></html>