Hi Josephine, The main error seems to occur in the raster package. The raster with logical values becomes numeric when a single value is changed using [].
a <- raster(ncol=10, nrow=10) a[] <- FALSE a[50] <- TRUE class(values(a)) In the code below I use a work-around that solves your problem for now (and changes some other minor issues in your code). map.test <- raster(ncol=10,nrow=10) map.test[] <- 100 origin <- raster(map.test) vals <- rep(FALSE, times=100) vals[93] <- TRUE origin[] <- vals goal <- raster(map.test) vals <- rep(FALSE, times=100) vals[9] <- TRUE goal[] <- vals tran.test <- transition(map.test, transitionFunction=mean, directions=8) passage(tran.test, origin, goal, theta=0.00001, totalNet="total") Best, Jacob. ________________________________ From: Josephine Walker <[email protected]> To: [email protected] Sent: Wednesday, 16 January 2013, 7:21 Subject: [R-sig-Geo] RasterLayer for origin and goal in passage function (gdistance) Hello everyone, I'm new to this list and to using R for geographical data analysis. I am playing around with the gdistance package but have a small problem: I am trying to use a RasterLayer to define origin and goal points for the passage function, which I believe is possible based on the documentation: origin SpatialPoints, matrix or numeric object with coordinates or RasterLayer object with origin cells set to TRUE goal SpatialPoints, matrix or numeric object with coordinates or RasterLayer object with origin cells set to TRUE Here is a basic idea of what I'm doing: #################################### map.test <- raster(ncol=10,nrow=10) map.test[] <- 100 origin <- raster(ncol=ncol(map.test),nrow=nrow(map.test)) origin[] <- FALSE origin[93] <- TRUE goal <- raster(ncol=ncol(map.test),nrow=nrow(map.test)) goal[] <- FALSE goal[9] <- TRUE tran.test <- transition(map.test,transitionFunction=mean,directions=8) passage(tran.test, origin, goal,theta=0,totalNet=total) and this gives the error message: Error in which(getValues(origin)) : argument to 'which' is not logical ################################## Any ideas what I'm doing wrong? Thanks very much Josephine [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-geo [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
