如何使用多边形切砖?

发布于 2024-10-16 22:02:34 字数 139 浏览 8 评论 0原文

我有一个bioclim变量的砖块文件,该砖块是由四个30秒的砖块合并而成的,所以它有点大。我想通过使用多边形作为边界进行切割来获取我的研究区域的砖块文件。我应该怎么办?否则,如果不可能用砖来做,我可以用光栅来做吗?

先谢谢啦~

马可

I have a brick file of the bioclim variables, the brick was merged from four 30sec tile brick, so it is a little bit large. I would like to get the brick file of my research area by cutting it using a polygon as boundary. What should I do? Otherwise, if it is not possible to do with brick, can I do it with raster?

Thanks in advance~

Marco

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深空失忆 2024-10-23 22:02:34

如果您想将砖块裁剪为较小的矩形,请查看 extent()。如果您想通过单击进行选择,也可以使用drawExtent()

编辑:由于您使用了术语“剪切”和“蒙版”,我不确定我是否理解正确,但这里有两种方法可能会有所帮助。您甚至可以同时使用两者。

# an example with dimensions: 77, 101, 3  (nrow, ncol, nlayers)
myGrid_Brick <- brick(system.file("external/rlogo.grd", package="raster"))

# a simple polygon within those dimensions
myTriangle_P <- Polygon(cbind(c(10, 80, 50, 10), c(10, 20, 65, 10)))
myTriangle_Ps <- Polygons(list(myTriangle_P), "fubar")
myTriangle_SP <- SpatialPolygons(list(myTriangle_Ps))
myTriangle_Ras <- rasterize(myTriangle_SP, myBrick)

# this will crop a brick to minimal rectangle that circumscribes the polygon
# extent(myCrop) is smaller than extent(myGrid) but no values are changed
myCrop_Brick <- crop(myGrid_Brick, myTriangle_SP)

# while this converts every coordinate that is NA in
# the mask to become NA in the returned brick
# while leaving the brick extent unchanged
myMask_Brick <- mask(myGrid_Brick, myTriangle_Ras)

Check out extent() if you want to crop the brick to a smaller rectangle. Also drawExtent() if you would rather choose by clicking.

EDIT: Since you used the terms "cut" and "mask" I am not sure I have understood correctly, but here are two ways that might help. You could even use both.

# an example with dimensions: 77, 101, 3  (nrow, ncol, nlayers)
myGrid_Brick <- brick(system.file("external/rlogo.grd", package="raster"))

# a simple polygon within those dimensions
myTriangle_P <- Polygon(cbind(c(10, 80, 50, 10), c(10, 20, 65, 10)))
myTriangle_Ps <- Polygons(list(myTriangle_P), "fubar")
myTriangle_SP <- SpatialPolygons(list(myTriangle_Ps))
myTriangle_Ras <- rasterize(myTriangle_SP, myBrick)

# this will crop a brick to minimal rectangle that circumscribes the polygon
# extent(myCrop) is smaller than extent(myGrid) but no values are changed
myCrop_Brick <- crop(myGrid_Brick, myTriangle_SP)

# while this converts every coordinate that is NA in
# the mask to become NA in the returned brick
# while leaving the brick extent unchanged
myMask_Brick <- mask(myGrid_Brick, myTriangle_Ras)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文