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

T C Wilkinson open at tobywilkinson.co.uk
Thu Jun 2 15:06:59 CEST 2016


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



More information about the R-sig-Geo mailing list