Hello,

I am trying to calculate the shortestPath from points in the ocean such
that the tracks will avoid land. I am using a raster file of the western
Atlantic Ocean where I have defined land to be 0 and water to be 1. After
making a transition layer, I am trying to use the shortestPath function to
look for the shortest path between two points on either side of Florida, to
assure that it would go around the peninsula.  When trying to do any sort
of shortestPath calculation, regardless if it is around land or not, I am
running into this error

"Error in get.shortest.paths(adjacencyGraph, indexOrigin, indexGoal) :
  At type_indexededgelist.c:1237 : cannot get neighbors, Invalid vertex id"

I have modeled my code after the genetic distance in Europe example found
in the gdistance vignette, and can get the code to work the way I want it
to with that dataset (only in that case the paths would avoid land) and so
I am not sure what is different in my case. Can anyone explain to me what
this error code means, and how I might go about fixing the problem. Any
guidance would be great. Thanks!

I'm not sure how to provide a sample dataset to produce the same error, but
here is what my code looks like. Sorry if this is not helpful.

>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  tools_2.14.0

>depth<-raster(depth)#land is 0, water is 1

>r<-flip(t(depth), direction="y")

>ext<-extent(c(round(min(lon)), round(max(lon)), round(min(lat)),
round(max(lat))))

>r<-setExtent(r, ext)

>projection(r)<-"+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"

>tr <- transition(r, mean, directions = 8)

>tR <- geoCorrection(tr, "r")

>tR

class       : TransitionLayer

dimensions  : 961, 1849, 1776889  (nrow, ncol, ncell)

resolution  : 0.04164413, 0.04162331  (x, y)

extent      : -101, -24, 9, 49  (xmin, xmax, ymin, ymax)

coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0

values      : conductance

matrix class: dsCMatrix

>matrixValues(tR)

[1] "conductance"

>sP1<-SpatialPoints(cbind(-79, 29))

>sP2<-SpatialPoints(cbind(-83.1, 28))

>sP3<-SpatialPoints(cbind(-70, 30))

>sPath<-shortestPath(tR, origin=p1, goal=p3, output="SpatialLines")

Error in get.shortest.paths(adjacencyGraph, indexOrigin, indexGoal) :

  At type_indexededgelist.c:1237 : cannot get neighbors, Invalid vertex id



-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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