我正在尝试在包 terra 中按行号和列号对栅格进行子集化。显然,这在栅格中很容易,至少没有地理范围和 crs: 使用 row/column index 对栅格进行子集。但我无法让它在 terra 中工作。必须有一个简单的方法。terra::subset 只选择栅格的图层。
期待有人问为什么:在对高程栅格进行采样并计算斜率和坡向之前,我用行和列填充了栅格,这依赖于相邻的单元格。现在我需要去掉那些填充的行和列。
library(terra)
EXT <- c( -108, -105, 39, 42 )
R <- rast( extent=EXT, ncol=14, nrow=14, crs="epsg:4326" )
R[] <- 1:ncell(R)
# Now try to strip off the outer 2 rows and columns
crop( x=R, y=ext( 3, 12, 3, 12 ) )
# Error: [crop] extents do not overlap
# Normal R-style subsetting also does not work,
# just gives values of that subset
R[ 3:12, 3:12 ]