簡體   English   中英

計算矩陣距離時R封裝距離的錯誤

[英]Error in R package gdistance while calculating a matrix distance

我正在嘗試使用函數costDistance是R包gdistance來計算點之間的矩陣距離,同時考慮到具有如下代碼的過渡矩陣的高度:

read.csv("subset.csv",h=T)->dat
llCRS <- CRS("+proj=longlat +ellps=WGS84")
dat_mat<- cbind(dat$Long, dat$Lat)
dat_sp <- SpatialPointsDataFrame(dat_mat, dat, proj4string = llCRS)
raster("subset.grd")->alt
alt[is.na(alt)] <- 0
heightDiff <- function(x){x[2] - x[1]}
tr <- transition(alt,heightDiff,8,symm=FALSE)
pC <- as.matrix(dat[c("Longitud", "Latitud")])
cosDist <- costDistance(tr, pC)

我收到此錯誤消息

Error in .Call("R_igraph_shortest_paths", graph, v - 1, to - 1, as.numeric(mode),  : 
  At structural_properties.c:5200 : cannot run Bellman-Ford algorithm, Negative loop detected while calculating shortest paths

如果有人知道為什么,那將非常有幫助。

在您的示例中,轉換函數應引發警告,指示出現負值。

這是避免它的方法:

heightDiff <- function(x){abs(x[2] - x[1])}

通常,您需要使用上面省略的函數geoCorrection。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM