Dear Jacob,


You're right, my points were disconnected. I replaced 0 values with very
smal values and it worked.

I didn't realize this could be a problem for defining an optimal path.

Maybe I should try to interpolate or preferably smooth my raster in order to
ensure there will be no 0 values between my niches. What do you think of it?


Thanks a lot and congratulations for the job, the library is great!

2011/8/12 Jacob van Etten <jacobvanetten@yahoo.com>

> Oh, but now it throws a straightforward error: "At
> structural_properties.c:4277 :Couldn't reach some vertices".
>
> This means that path between A and B does not exist, because they are on
> different unconnected "islands". Try again, after giving a small positive
> value to all raster cells that are 0 now.
>
> Something like:
>
> rognes.r[rognes.r<1] <- 1
>
> You don´t have to transform the layer.
>
> Having an NA crs slot in your raster is not a problem in your case, because
> isLonLat(rognes.r) would give FALSE, which is what you want.
>
> Jacob.
>
> --- On Fri, 12/8/11, Mathieu Rajerison <mathieu.rajerison@gmail.com>
> wrote:
>
> > From: Mathieu Rajerison <mathieu.rajerison@gmail.com>
> > Subject: Re: [R-sig-Geo] gdistance, shortest path => "cannot derive
> coordinates from non-numeric matrix"
> > To: r-sig-geo@r-project.org
> > Date: Friday, 12 August, 2011, 9:17
> > The problem seems to come from my
> > raster values.
> >
> > 1) With all values equal to 1, as in your example, it
> > works
> >
> > > rognes.r
> > class : RasterLayer
> > dimensions : 389, 363, 141207 (nrow, ncol, ncell)
> > resolution : 25, 25 (x, y)
> > extent : 885426, 894501, 6283406, 6293131 (xmin, xmax,
> > ymin, ymax)
> > coord. ref. : +proj=utm +zone=31
> > values : in memory
> > min value : 1
> > max value : 1
> > >(...)
> > OK, the path is calculated
> >
> >
> > 2) But with my original raster, it doesn't.
> > > rognes.r
> > class : RasterLayer
> > dimensions : 389, 363, 141207 (nrow, ncol, ncell)
> > resolution : 25, 25 (x, y)
> > extent : 885426, 894501, 6283406, 6293131 (xmin, xmax,
> > ymin, ymax)
> > coord. ref. : +proj=utm +zone=31
> > values : in memory
> > min value : 0
> > max value : 100
> >
> > > summary(rognes.r)
> > Cells: 141207
> > NAs : 0
> > Min. 0.00
> > 1st Qu. 0.00
> > Median 0.00
> > Mean 16.03
> > 3rd Qu. 0.00
> > Max. 100.00
> >
> > > rognes.t = transition(rognes.r, transitionFunction =
> > mean, directions=8)
> > > A = c(887543,6286048)
> > > B = c(890911,6289681)
> > > path = shortestPath(rognes.t, A, B,
> > output="SpatialLines")
> > Erreur dans .local(obj, ...) :
> > cannot derive coordinates from non-numeric matrix
> > De plus : Message d'avis :
> > In get.shortest.paths(adjacencyGraph, indexOrigin,
> > indexGoal) :
> > At structural_properties.c:4277 :Couldn't reach some
> > vertices
> >
> > Do you see any problem with my raster values?
> >
> > 2011/8/12 Mathieu Rajerison <mathieu.rajerison@gmail.com>
> >
> > > I've not specified crs reference when I created my
> > raster which is in
> > > EPSG:2154. Is it a problem?
> > >
> > > Do I have to reproject it from EPSG:2154 to Lon/Lat
> > before using
> > > TransitionLayer calculations?
> > >
> > >
> > > My sessionInfo() is as follows:
> > > R version 2.13.1 (2011-07-08)
> > > Platform: i386-pc-mingw32/i386 (32-bit)
> > >
> > > locale:
> > > [1] LC_COLLATE=French_France.1252
> > LC_CTYPE=French_France.1252
> > > [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C
> > > [5] LC_TIME=French_France.1252
> > >
> > > attached base packages:
> > > [1] stats graphics grDevices utils datasets methods
> > base
> > >
> > > other attached packages:
> > > [1] maptools_0.8-9 foreign_0.8-44 gdistance_1.1-1
> > > [4] Matrix_0.999375-50 lattice_0.19-30 igraph_0.5.5-2
> > > [7] spatstat_1.22-3 RandomFields_2.0.45 deldir_0.0-14
> > > [10] mgcv_1.7-6 raster_1.8-39 sp_0.9-83
> > >
> > > loaded via a namespace (and not attached):
> > > [1] grid_2.13.1 nlme_3.1-101 tools_2.13.1
> > >
> > >
> > > Thanks for the quick answer!
> > >
> > > 2011/8/11 Jacob van Etten <jacobvanetten@yahoo.com>
> > >
> > >> Dear Mathieu,
> > >>
> > >> From what I can see, the error is not due to the
> > TransitionLayer, but is
> > >> about the coordinates.
> > >>
> > >> The following code works with the versions of
> > gdistance and raster that
> > >> are currently on CRAN (gdistance_1.1-1,
> > raster_1.9-5):
> > >>
> > >> library(gdistance)
> > >> rognes.r <- raster(nrows=50, ncols=50,
> > xmn=887000, xmx=892000,
> > >> ymn=6285000, ymx=6290000, crs="+proj=utm
> > +zone=31")
> > >> rognes.r[] <- 1
> > >> rognes.t = transition(rognes.r, transitionFunction
> > = mean, directions=8)
> > >> A = c(887543,6286048)
> > >> B = c(890911,6289681)
> > >> path = shortestPath(rognes.t, A, B,
> > output="SpatialLines")
> > >>
> > >> Next time, provide the results of sessionInfo()
> > when you post to this
> > >> list. Also, try to provide reproducible code (like
> > in my example). With the
> > >> information you give now, I can only guess the
> > cause of your problem.
> > >>
> > >> Jacob
> > >>
> > >> --- On Thu, 11/8/11, Mathieu Rajerison <mathieu.rajerison@gmail.com>
> > >> wrote:
> > >>
> > >> > From: Mathieu Rajerison <mathieu.rajerison@gmail.com>
> > >> > Subject: [R-sig-Geo] gdistance, shortest path
> > => "cannot derive
> > >> coordinates from non-numeric matrix"
> > >> > To: r-sig-geo@r-project.org
> > >> > Date: Thursday, 11 August, 2011, 17:59
> > >> > Hi,
> > >> >
> > >> >
> > >> > I'm using gdistance to  determine
> > optimal wildlife
> > >> > corridors. My transition
> > >> > layer's name is rognes.t, rognes being a
> > city  name.
> > >> >
> > >> > I want to determine a corridor between two
> > major ecologic
> > >> > niches with
> > >> > centroids coordinates A and B.
> > >> >
> > >> > But when launching shortestPath, i get the
> > following
> > >> > error:
> > >> > > rognes.t = transition(rognes.r,
> > transitionFunction =
> > >> > mean, directions=8)
> > >> > > A = c(887543,6286048)
> > >> > > B = c(890911,6289681)
> > >> > > path = shortestPath(rognes.t, A, B,
> > >> > output="SpatialLines")
> > >> > Erreur dans .local(obj, ...) :
> > >> > cannot derive coordinates from non-numeric
> > matrix
> > >> > De plus : Message d'avis :
> > >> > In get.shortest.paths(adjacencyGraph,
> > indexOrigin,
> > >> > indexGoal) :
> > >> > At structural_properties.c:42
> > >> >
> > >> > My transitionMatrix has these
> > characteristics:
> > >> > > min(transitionMatrix(rognes.t));
> > >> > max(transitionMatrix(rognes.t));
> > >> > mean(transitionMatrix(rognes.t))
> > >> > [1] 0
> > >> > [1] 100
> > >> > [1] 0.0009044702
> > >> >
> > >> > All values are numeric..
> > >> >
> > >> >
> > >> > Any help would be greatly appreciated,
> > >> >
> > >> > mathieu
> > >> >
> > >> >     [[alternative HTML
> > version deleted]]
> > >> >
> > >> >
> > _______________________________________________
> > >> > R-sig-Geo mailing list
> > >> > R-sig-Geo@r-project.org
> > >> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> > >> >
> > >>
> > >
> > >
> >
> >     [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>

	[[alternative HTML version deleted]]

