Hello,

I am trying to find the shortest paths from one origin to multiple
destinations. The package seems to indicate that this sort of calculation
should be possible but I am getting an error when I use multiple
destinations, and choose the output="SpatialLines". As you will see in my
example below, I do not get an error if I retain the default output type.
Is this calculation not possible with the "SpatialLines" output type, or am
I feeding the function points in an incorrect format?
Thank you for any help/guidance you can provide.


This code is adapted from an example and should be reproducible.

>require(gdistance)
>sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C                 LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] fields_6.6.1    spam_0.27-0     ncdf4_1.4       gdistance_1.1-2
[5] Matrix_1.0-1    lattice_0.20-0  igraph_0.5.5-4  raster_1.9-33
[9] sp_0.9-91

loaded via a namespace (and not attached):
[1] grid_2.14.0

#Create a new raster and set all its values to unity.
>raster <- raster(nrows=18, ncols=36)
>raster <- setValues(raster,rep(1,ncell(raster)))
#Create a Transition object from the raster
>tr <- transition(raster,mean,4)
>tr
class       : TransitionLayer
dimensions  : 18, 36, 648  (nrow, ncol, ncell)
resolution  : 10, 10  (x, y)
extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84
values      : conductance
matrix class: dsCMatrix

#Create two sets of coordinates
>sP1 <- SpatialPoints(cbind(65,-35))
>sP2 <- SpatialPoints(cbind(c(50,15,-40),c(80,20,-5)))
>sP2
SpatialPoints:
     coords.x1 coords.x2
[1,]        50        80
[2,]        15        20
[3,]       -40        -5
Coordinate Reference System (CRS) arguments: NA

#Calculate the shortest path
>sPath1 <- shortestPath(tr, sP1, sP2)
>sPath1
class       : TransitionLayer
dimensions  : 18, 36, 648  (nrow, ncol, ncell)
resolution  : 10, 10  (x, y)
extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84
values      : conductance
matrix class: dsCMatrix

>sPath2 <- shortestPath(tr, sP1, sP2, output="SpatialLines")
Error in Lines(linesList, ID = as.character(1:length(shortestPaths))) :
  Single ID required


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Danielle Haulsee
Graduate Student
College of the Earth, Ocean and Environment
University of Delaware

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to