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

Ben Tupper btupper @ending from bigelow@org
Thu Jul 12 14:12:28 CEST 2018


Hi,

You may have solved this already, but I get tripped up on the "the distance from all not NA cells in a raster".  Is it the distance each NA cell is from each non-NA cell?  Also, I'm wondering why you want to know the distance to ALL non-NA cells - what is your big-picture purpose for wanting these distances?  

Cheers,
Ben

> On Jul 6, 2018, at 12:22 PM, Gregovich, Dave P (DFG) <dave.gregovich using alaska.gov> wrote:
> 
> 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]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list