[R-sig-Geo] Error-message-when-trying-to-compute-the-least-cost-path-in-gdistance-in-R
chris english
englishchristophera at gmail.com
Wed Nov 30 03:32:04 CET 2016
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.
> r <- raster(nrows = 1560, ncols = 1560)
> r <- setValues(r, runif(ncell(r)))
> trCost <- transition(r, transitionFunction = mean, directions = 8)
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:
> http://r-sig-geo.2731867.n2.nabble.com/Error-message-when-
> trying-to-compute-the-least-cost-path-in-gdistance-in-R-tt7590273.html
>
> Hi everyone,
>
> I have a similar problem. I have two points that I want to join in one line
> "SpatialLines"
>
> class(trCost)#"TransitionLayer"+attr gdistance
> summary(trCost)#1560 x 1560 sparse Matrix of class "dsCMatrix", with 8
> entries
>
> pts1<-cbind(x=-27.54572,y=38.30128)
>
> pts2<-cbind(x=-28.59933,y=37.32453)
> #
> class(pts1)#matrix
> class(pts2)#matrix
> #
> is.numeric(pts1)#[1] TRUE
>
> plot(shortestPath(trCost, pts[1,], pts[2,], output="SpatialLines"),
> add=TRUE)
> Error in if (is.numeric(v) && any(v < 0)) { :
> missing value where TRUE/FALSE needed
>
> Thanks in advance
>
> Marta
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list