简体   繁体   English

R - terra::distance() 等效于 raster::gridDistance(..., origin = x, omit = y)

[英]R - terra::distance() equivalent of raster::gridDistance(..., origin = x, omit = y)

UPDATE<\/strong> - this question relates to terra 1.4-1<\/code> , and is now obsolete with terra 1.5-12<\/code> (or earlier?).更新<\/strong>- 这个问题与terra 1.4-1<\/code> ,现在已经过时terra 1.5-12<\/code> (或更早版本?)。


I am looking for the terra<\/code> equivalent of raster::gridDistance(..., origin = my_origin, omit = my_omit)<\/code> .我正在寻找raster::gridDistance(..., origin = my_origin, omit = my_omit)<\/code>的terra<\/code>等价物。

I found what looks to be an old webpage on terra::gridDistance<\/code> , from terra v0.2-8<\/code> here<\/a> , but from what I can gather terra::distance<\/code> is the current replacement for raster::gridDistance<\/code> ( list of terra's<\/code> replacement functions here<\/a> ).我在terra::gridDistance<\/code>上发现了一个旧网页,来自terra v0.2-8<\/code> here<\/a> ,但从我可以收集到的terra::distance<\/code>是raster::gridDistance<\/code>的当前替代品(此处terra's<\/code>替代功能列表<\/a>)。

However, I don't know to implement omit = my_omit<\/code> (or equivalent) in terra::distance<\/code> .但是,我不知道在terra::distance<\/code>中实现omit = my_omit<\/code> (或等效项)。 From the documentation page<\/a> it looks like any non-NA is deemed the origin<\/code> , but there is no reference to omit<\/code> , or the option to change the origin<\/code> to a specific value (unlike the raster::gridDistance<\/code> example below).文档页面<\/a>看来,任何非 NA 都被视为origin<\/code> ,但没有提及omit<\/code> ,也没有将origin<\/code>更改为特定值的选项(与下面的raster::gridDistance<\/code>示例不同)。

This is the example from raster::gridDistance<\/code> :这是raster::gridDistance<\/code>的示例:

library(raster)

# world lon/lat raster
r <- raster(ncol=10,nrow=10, vals=1)
r[48] <- 2     # this will be the origin
r[66:68] <- 3  # this will be the area that can't be traversed
plot(r)

d <- gridDistance(r,origin=2,omit=3) 
plot(d)

Thanks to @lovalery for pointing this out in the comments.感谢@lovalery 在评论中指出这一点。

In the original question I was using terra 1.4-1 .在最初的问题中,我使用的是terra 1.4-1 As of January 2022, terra 1.5-12 has been released (Jan 13th 2022), and it now includes a terra::gridDistance() function which is very similar to the raster::gridDistance() function.截至 2022 年 1 月, terra 1.5-12已发布(2022 年 1 月 13 日),它现在包含一个与raster::gridDistance()函数非常相似的terra::gridDistance() () 函数。

For the sake of completeness, this is the example from ?terra::gridDistance :为了完整起见,这是来自?terra::gridDistance的示例:

#world lon/lat raster
r <- rast(ncol=10,nrow=10, vals=1)
r[48] <- 2
r[66:68] <- 3
d <- gridDistance(r,origin=2,omit=3) 
plot(d)

#UTM small area
crs(r) <- "+proj=utm +zone=15 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"
d <- gridDistance(r,origin=2,omit=3) 
plot(d)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM