Skip to content
Prev 25148 / 29559 Next

Error-message-when-trying-to-compute-the-least-cost-path-in-gdistance-in-R

Marta,

I don't know what constructed your trCost (1560 x 1560 sparse Matrix of
class "dsCMatrix") which I take to be symmetric of
8 directions.
All I can find to the moment is a little problem of naming in the
shortestPath function call

i.e. pts1 and pts2 are matrix objects (like coordinates), presumably to be
start and goal.

and if they are written as:

plot(shortestPath(trCost, pts1[1,], pts2[1,], output="SpatialLines"))
you get a plot
# without add=TRUE in my case as
# with add=TRUE it reminds me I haven't called plot yet hence nothing to
add to:
Error in plot.xy(xy.coords(x, y), type = type, ...) :
  plot.new has not been called yet


rather than:

plot(shortestPath(trCost, pts[1,], pts[2,], output="SpatialLines"))
which gives this error:

Error in shortestPath(tr, pts[1, ], pts[2, ], output = "SpatialLines") :
  object 'pts' not found


So I imagine that isn't what you had in your call


the Error, generally otherwise would point to NA(s) in the matrix (trCost).
Well. I'm guessing.

HTH,

Chris
On Mon, Nov 28, 2016 at 1:05 PM, marta azores <martazores at gmail.com> wrote: