【发布时间】:2020-06-29 20:02:40
【问题描述】:
我正在尝试在 R 中运行“计算”函数,但似乎无法找到获取正在处理的单元格坐标的方法。我想做的很简单: 在二进制栅格(0 和 1)上使用“计算”功能——如果栅格值为“0”,则更改为“NA”。如果栅格值为“1”,则应用一系列过程,我需要将单元坐标存储到变量中。
processAllCells = function(cell) {
if (cell == 0) {
cell = NA
return(cell)
}
else {
cellCoords = coordinates(cell) ### This is what I'm trying to do. This does not work. See the error message.
### Here will go further processes using the cell coordinates.
return(cell)
}
}
outputRaster = calc(lake, processAllCells)
错误信息:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘coordinates’ for signature ‘"integer"’
In addition: Warning message:
In if (cell == 0) { :
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘coordinates’ for signature ‘"integer"’
谢谢大家!
【问题讨论】:
-
您是从某个库中导入
coordinates函数还是您自己编写的? -
这是一个从包'raster'中定义的函数。
-
该函数需要一个对象来计算坐标,而不是整数或整数向量。这可能是您遇到的问题。
-
是的,这正是问题所在。变量“cell”只包含它的值,所以是“1”。但我想知道是否有人知道我如何获得它的坐标。
标签: r coordinates raster r-raster calc