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

Jacob van Etten jacobvanetten at yahoo.com
Thu Jun 2 19:23:23 CEST 2016


I saw that my mail application does not respect the line breaks...
Here the correct R code.
# value zerocost <- c(0)
adj <- 1
# your complicated formula
1 / ((((1337.8 * cost[adj]^6) + (278.19 * cost[adj]^5) - (517.39 * cost[adj]^4) - (78.199 * cost[adj]^3) + (93.419 * cost[adj]^2) + (19.825 * cost[adj]) + 1.64)))[1] 0.6097561 

    On Thursday, 2 June 2016, 7: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



  
	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list