the problem i am trying to solve is that i want to extract the value of pixels of multiple rasters using a shapefile containing multiple point locations , for each point i would like to extract the value of multiple rasters "time series" , and also loop through a list of buffer radiuses to be input in the extract function , the end result i want is a csv for each station for each buffer
as far i did manage to write a program under R with the raster library , my code is composed in two loops , the first loop goes into each raster and extract the pixel value corresponding to the locations of multiple locations in a shapefile , the second one contains a list of radiuses to be looped to extract the means , max, and min of each pixel radiuses
but the code is too loose at this point without effective integration of the radius loop
library(raster)
library(rgdal)
library(stringr)
library(ggplot2)
library(lubridate)
raster_files <- list.files('J:/nvc',pattern="*.tif",full.names = T)
r_name<- list.files(path='J:/nvc',pattern="*.tif",full.names = F)
shape<-readOGR('J:/nvc/locations/locations.shp')
radius <- read.csv('J:/nvc/radius.csv')
rList <- list()
statList <- list()
for (j in 1:nrow(radius)){
for(i in 1:length(raster_files)){
ras <- raster(raster_files[i])
stack <- stack(ras)
crs(stack) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84"
mean <- raster::extract(stack,shape,buffer=j,fun=mean,df=TRUE)
min <- raster::extract(stack,shape,buffer=j,fun=max,df=TRUE)
max <- raster::extract(stack,shape,buffer=j,fun=min,df=TRUE)
Name <- r_name[i]
statList[[i]] <- data.frame(max)
df <- do.call(rbind.data.frame,statList)
}
}
N.B : i am just naming 3 locations to try , alpha bravo and charlie
and for the radiuses it's 1,2,4,6,8,10,20 km
the rasters are named 1h-2020042601 , 1h-2020042602,1h-2020042603 ..... e.g : 1 raster for each hour