【发布时间】:2020-07-04 17:21:26
【问题描述】:
我要解决的问题是我想使用包含多个点位置的 shapefile 提取多个栅格的像素值,对于每个点我想提取多个栅格“时间序列”的值,并且还循环遍历要在提取函数中输入的缓冲区半径列表,我想要的最终结果是每个缓冲区的每个站点的 csv
到目前为止,我确实设法使用光栅库在 R 下编写了一个程序,我的代码由两个循环组成,第一个循环进入每个光栅并提取与 shapefile 中多个位置的位置相对应的像素值,第二个包含要循环以提取每个像素半径的均值、最大值和最小值的半径列表
但此时代码过于松散,没有有效集成半径循环
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)
}
}
注意:我只是命名 3 个尝试的地点,alpha bravo 和 charlie
半径为 1,2,4,6,8,10,20 公里
栅格被命名为 1h-2020042601 , 1h-2020042602,1h-2020042603 ..... 例如:每小时 1 个栅格
【问题讨论】:
标签: python r gis raster r-raster