R 裁剪栅格的无数据 [英] R Crop no-data of a raster
本文介绍了R 裁剪栅格的无数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想裁剪一些栅格的无数据部分(1 中的图像示例 其中 no-data 为黑色),无需手动定义范围.
I would like to crop the no-data part of some rasters (example of the image in 1 where no-data is in black) without defining the extent manually.
有什么想法吗?
推荐答案
您可以使用 trim
删除只有 NA
值的外部行和列:
You can use trim
to remove exterior rows and columns that only have NA
values:
library(raster)
r <- raster(ncols=18,nrows=18)
r[39:49] <- 1
r[205] <- 6
s <- trim(r)
要将其他值更改为 NA
或从 NA
更改,您可以使用 reclassify
.例如,将 NA
更改为 0:
To change other values to or from NA
you can use reclassify
. For example, to change NA
to 0:
x <- reclassify(r, cbind(NA, 0))
这篇关于R 裁剪栅格的无数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文