[R-sig-Geo] Distance from not NA cells in a raster

Gregovich, Dave P (DFG) d@ve@gregovich @ending from @l@@k@@gov
Fri Jul 6 18:22:48 CEST 2018


Hi,
I would like to obtain the distance from all not NA cells in a raster. This works for smaller rasters, but seems difficult for the size of rasters (~ 8000 pixel square)  I am working with.
Below is what I've tried. I would be OK calling other software from R, or using some parallelization, if it might help.
Thanks so much for your help!  If I could just calculate this distance in two hours or less (or so) I would be satisfied.
Dave.

rm(list=ls())
library(raster)

#make raster
rast <- raster(nrow = 8000, ncol = 8000, ext = extent(0,1,0,1))

#generate cells to calculate distance from.
rast[sample(8000^2, 10000)] <- 1

#try two different methods...
dist1 <- gridDistance(rast, origin = 1)#throws an error after x minutes
#'Error: cannot allocate vector of size 3.8 Gb'
dist2 <- distance(rast)#ran all night, R was hung up in the morning and had to force shutdown.

___________________________________________
Dave Gregovich
Research Analyst
Alaska Department of Fish and Game
Division of Wildlife Conservation
802 3rd Street
Douglas, AK 99824
907-465-4291
___________________________________________


	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list