如何解决如何通过R中shapefile的精确轮廓来屏蔽光栅?
我正在尝试通过 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 举报,一经查实,本站将立刻删除。