英文:
cropping raster using polygon not selecting all cells in terra package
问题
我有一个栅格图像,正在尝试使用多边形进行裁剪。
这是我的多边形:
我的栅格文件包含整个地球,分辨率为0.25度,所以我使用多边形对栅格进行了裁剪:
library(terra)
crop_raster <- terra::crop(temp_rast, county_ref)
plot(crop_raster)
plot(county_ref, add = T)
这种裁剪看起来有点奇怪,因为只选择了2个栅格单元。我原本希望看到像下面这样的结果,使用 snap = "out"
参数可以得到:
crop_raster_snap <- terra::crop(temp_rast, county_ref, snap = "out")
plot(crop_raster_snap)
plot(county_ref, add = T)
为什么在第一次裁剪时 crop
参数没有起作用?以及 snap
参数的目的是什么?
英文:
I have a raster and I am trying to crop it using a polygon
This is my polygon:
My raster file contains the entire globe at 0.25 degree resolution so I cropped the raster using the polygon:
library(terra)
crop_raster <- terra::crop(temp_rast, county_ref)
plot(crop_raster)
plot(county_ref, add = T)
This cropping looks odd since only 2 raster cells are selected. I was expecting something like below which I get using the snap = "out"
argument.
crop_raster_snap <- terra::crop(temp_rast, county_ref, snap = "out")
plot(crop_raster_snap)
plot(county_ref, add = T)
Why didn't the crop argument worked in the first instance? And what is the purpose of the 'snap' argument?
答案1
得分: 0
crop
函数的文档,使用 x
作为 SpatRaster 参数,以及使用 y
作为 SpatExtent(或另一个空间对象的范围)参数;参数 "snap" 的选项如下:
- "near":用于将
y
对齐到x
的几何形状 - "in":用于向内裁剪(减小区域)
- "out":用于向外裁剪(增大区域)
- "out":用于将
y
对齐到距离最近的边界,因为您不能裁剪部分行或列。您只能裁剪整行或整列。因此,您有三种选项,向内裁剪(减小区域)、向外裁剪(增大区域)或对齐到最近的边界。
英文:
The documentation of crop
, with SpatRaster argument x
, and SpatExtent (or the extent of another spatial object) argument y
; that argument "snap" is
> One of "near", "in", or "out". Used to align y to the geometry of x
y
needs to be aligned to the geometry of x
because you cannot crop partial rows or columns. You can only crop entire rows or columns. So you have three options, go inwards (smaller area), outwards (larger area) or to the border that is nearest.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论