[R-sig-Geo] gdistance transition objects: dealing with NAs in source cost raster

chris english englishchristophera at gmail.com
Thu Jun 2 15:29:38 CEST 2016


Toby,

This may seem silly, and a thousandth of something is not zero, but perhaps
this is  a kind of preallocation issue and using Jacob's if else with 0.0
as else might do the trick.

Fingers crossed?
Chris
On Jun 2, 2016 16:07, "T C Wilkinson" <open at tobywilkinson.co.uk> wrote:

> Dear Jacob,
>
> Many thanks for fast reply. [Apologies for the typo and potential
> confusion on gdistance, I am still relative new to R — and thus borrowing
> camelCase habit from previous coding.]
>
> I’ve tried your suggested re-worked function to avoid NA in the
> transition, but I still get the same result.
>
> When plotted, the `plot(raster(conductance))` still colours the sea (i.e.
> doesn’t show it in the colNA colour) and the resultant accCosts etc include
> the sea as part of the result surface.
>
> An interactive `click(raster(conductance))` reveals the sea to be a
> uniform value of 0.001436461.
>
> Thanks again,
> Toby
>
>
>
> On 2 June 2016 at 12:30:43, Jacob van Etten (jacobvanetten at yahoo.com)
> wrote:
> > Dear Toby,
> > TransitionLayers should normally not hold NA values. If you want to set
> cell connections
> > to zero conductance, the transitionFunction should give a value zero if
> it finds an NA.
> > Your function gives an NA as result, which is not what you want:
> > ifelse(((!is.na(x[2])) & (!is.na(x[1]))),(x[2] - x[1]),NA)
> >
> > You probably want to do:
> > ifelse(((!is.na(x[2])) & (!is.na(x[1]))), (x[2] - x[1]), 0)
> >
> > Also, note that gDistance is not the name of the package.
> > Best,
> > Jacob
>
> _______________________________________________
> 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