[R-sig-Geo] supplying multiple coordinates to shortestPath

Pascal Title ptitle at umich.edu
Thu Feb 5 05:55:57 CET 2015


Hi,

In the shortestPath( ) function of the R package gdistance, the
documentation seems to imply (at least according to my interpretation) that
I should supply one point as a starting coordinate, but that I should be
able to supply a matrix of coordinates as endpoints for path calculations.
However, if I try this, I get an error. Am I doing something wrong, or am I
misinterpreting the documentation?

See code below. All advice greatly appreciated!

-Pascal

CODE:

require(maptools)
require(gdistance)

#create world raster
data(wrld_simpl)
r <- raster()
r <-rasterize(wrld_simpl, r, progress='text')

#make land off bounds
r[is.na(r)] <- -999
r[r > -999] <- NA
r[r == -999] <- 1

tr <- transition(r, mean, directions = 8)
tr <- geoCorrection(tr, "c")

coordmat <- cbind(c(0,-150,150), c(0, 20, 20))

#single coordinates supplied -- works
shortestPath(tr, coordmat[1,], coordmat[2,], output='SpatialLines')

#multiple coordinates supplied to 'goal', returns error
shortestPath(tr, coordmat[2,], coordmat, output='SpatialLines')

Error in .local(obj, ...) :
  cannot derive coordinates from non-numeric matrix

-- 

Pascal Title
PhD candidate | Rabosky Lab
Dept of Ecology and Evolutionary Biology
University of Michigan
ptitle at umich.edu

pascaltitle.weebly.com

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list