问题描述
我正在尝试通过 shapefile 屏蔽栅格。所以,我使用了以下代码:
mat=matrix(colMeans(x),nrow=length(lon(x)),ncol=length(lat(x)))
# x is gridded rainfall data
mat_new <- apply(t(mat),2,rev)
library(raster)
r=raster(mat_new,xmn=min(lon(x)),xmx=max(lon(x)),ymn=min(lat(x)),ymx=max(lat(x)))
r2 <- mask(r,shp_proj)
plot(r2)
plot(shp_proj,add=T)
以及以下输出: enter image description here
mat=matrix(colMeans(x),ymx=max(lat(x)))
shp_ras <- rasterize(shp_proj,r,getCover=TRUE)
shp_ras[shp_ras==0] <- NA
plot(mask(r,shp_ras))
plot(shp_proj,add=T)
并获得以下输出: enter image description here
然而,这也不是想要的输出。我想通过 shapefile 的精确轮廓裁剪栅格。我想要如下输出: enter image description here
有什么办法可以在 R 中实现这一点吗?请帮忙。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)