使用 R 提取单个国家/地区的 WORLDCLIM 数据

Extract WORLDCLIM data using R for a single country

我想使用 R 提取印度一个国家的最低和最高温度的世界气候数据,并将其保存为数据集(与我自己的包含地区一级作物产量的数据集一起使用)。 我浏览了几篇文章,发现这可以在 R 中轻松完成,但是我尝试关注的文章在命令或序列方面有点不同,我感到很困惑。 (https://gis.stackexchange.com/questions/259478/worldclim-data-na-for-my-coordinates, https://gis.stackexchange.com/questions/227585/using-r-to-extract-data-from-worldclim

我尝试使用的如下。

library(raster)
library(sp)
r<- getData('CMIP5', var='tmin', res=10, rcp=45, model='HE', year=70)
r <- r[[c(1,12)]]
values <- extract(r,points)
df <- cbind.data.frame(coordinates(points),values)
head(df)

但是,我只能 运行 前两行和行值

<- extract(r,points) gives the error Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘extract’ for signature ‘"RasterStack", "function"’

有什么建议吗?

这是解决方法

library(raster)
library(sp)
library(rgeos)
library(rgdal)
library(sf)

r<- getData('CMIP5', var='tmin', res=10, rcp=45, model='HE', year=70)

#Using Zonal statistics
poly <- shapefile("Provide_your_drive_name" e.g. "F:\Kriging in R\India Shape files\2011_Dist.shp")
plot(poly)

#This will take considerable time
ex <- extract(r, poly, fun='mean', na.rm=TRUE, df=TRUE, weights = TRUE) 

write.csv(cbind(poly$DISTRICT,ex),"Worldclim.csv", row.names = F)

# using centroids
nc <- st_read(dsn="Provide_your_drive_name" e.g. "F:\Kriging in R\India Shape files", layer="2011_Dist")
# just view the attributes & first 6 attribute values of the data
head(nc)
sp_cent <- gCentroid(as(nc, "Spatial"), byid = TRUE)
values <- extract(r,sp_cent)

write.csv(cbind(as.data.frame(nc$DISTRICT),as.data.frame(values)),"Worldclim_centroids.csv", row.names = F)