2016-04-09 6 views
0

RgdistanceのaccCost()とcostDistance()関数は、ソース座標Aから目的座標Bに移動するときに異なる値を生成します。Bのコスト累積値は、等価な異方性遷移行列が与えられ、両方の関数がDijkstraアルゴリズムを使用すると、AからBまでのcostDistance値?R:accCostとcostDistanceのgdistanceの結果が異なる

もしそうでなければ、計算の根本的な違いは何ですか?そうであれば、以下に示すコードから得られたさまざまな値をどのように説明しますか?この例では、AからBのcostDistance = 0.13時間で、accCost = 0.11時間のB点で実行されます。私の他のテストでは、accCostは一貫してcostDistanceより小さく、そのまま維持しています。コードは、accCostのドキュメントに記載されている例に基づいています。

require(gdistance) 
r <- raster(system.file("external/maungawhau.grd", package="gdistance")) 
altDiff <- function(x){x[2] - x[1]} 
hd <- transition(r, altDiff, 8, symm=FALSE) 
slope <- geoCorrection(hd) 
adj <- adjacent(r, cells=1:ncell(r), pairs=TRUE, directions=8) 
speed <- slope 
speed[adj] <- 6 * 1000 * exp(-3.5 * abs(slope[adj] + 0.05))#1000 to convert to a common spatial unit of meters 
Conductance <- geoCorrection(speed) 
A <- matrix(c(2667670, 6479000),ncol=2) 
B <- matrix(c(2667800, 6479400),ncol=2) 
ca <- accCost(Conductance,fromCoords=A) 
extract(ca,B) 
costDistance(Conductance,fromCoords=A,toCoords=B) 
+0

再現可能な例を示してください。 http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example –

+0

"require(gdistance)"という行を追加しました。この例では、完全に再現可能な例にする必要があります。 – RandyHaas

答えて

1

違いはありません。 accCostの現在のバージョンでは、igraphパッケージの変更に起因する小さなバグがあります。

この機能が問題を解決しているかどうかをご確認ください。

setMethod("accCost", signature(x = "TransitionLayer", fromCoords = "Coords"), 
def = function(x, fromCoords) 
    { 
    fromCoords <- .coordsToMatrix(fromCoords) 
    fromCells <- cellFromXY(x, fromCoords) 
    if(!all(!is.na(fromCells))){ 
     warning("some coordinates not found and omitted") 
     fromCells <- fromCells[!is.na(fromCells)] 
    } 
    tr <- transitionMatrix(x) 
    tr <- rBind(tr,rep(0,nrow(tr))) 
    tr <- cBind(tr,rep(0,nrow(tr))) 

    startNode <- nrow(tr) #extra node to serve as origin 
    adjP <- cbind(rep(startNode, times=length(fromCells)), fromCells) 

    tr[adjP] <- Inf 

    adjacencyGraph <- graph.adjacency(tr, mode="directed", weighted=TRUE) 
    E(adjacencyGraph)$weight <- 1/E(adjacencyGraph)$weight  

    shortestPaths <- shortest.paths(adjacencyGraph, v=startNode, mode="out")[-startNode] 

    result <- as(x, "RasterLayer") 
    result <- setValues(result, shortestPaths) 
    return(result) 
    } 
) 
+0

ありがとうございます。私はこれを試して、次のエラーが表示されます:エラーAccCost(コンダクタンス、fromCoords = A): 関数 ".coordsToMatrix" – RandyHaas

+0

を見つけることができませんでしたここでその関数を取得する場合にのみ申し訳ありません:https:// r- forge.r-project.org/scm/viewvc.php/pkg/gdistance/R/internal-functions.R?view=markup&revision=222&root=gdistanceこれは一時的な解決策であり、すぐに解決する必要があります。 – JacobVanEtten

+0

これは機能します。どうもありがとうございました。 – RandyHaas

0

この問題は、gdistance 1.2-1で解決されています。

関連する問題