使用R提取单个国家的WORLDCLIM数据 [英] Extract WORLDCLIM data using R for a single country

查看:595
本文介绍了使用R提取单个国家的WORLDCLIM数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用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

I want to extract world climate data for minimum and maximum temperature for only one country India using R and save it as a data set (to use with my own data-set that contains crop yields at the district level). I have gone through several posts and can see that this can be done easily in R, however the posts that I have tried to follow are a bit different in terms of the commands or sequences and I am getting confused. (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

我尝试使用的方法如下.

What I have tried to use is as follows.

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)

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

However, I can run only the first two lines and the line values

<- 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)

这篇关于使用R提取单个国家的WORLDCLIM数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆