[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 19:47:48 CEST 2018
Sorry, I forgot to include session info to associate my issue...thanks!
> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
other attached packages:
[1] RSAGA_1.2.0 plyr_1.8.4 shapefiles_0.7 foreign_0.8-69 gstat_1.1-6 rgdal_1.2-16
[7] raster_2.6-7 sp_1.2-5
From: Gregovich, Dave P (DFG)
Sent: Friday, July 06, 2018 8:23 AM
To: 'r-sig-geo using r-project.org'
Subject: Distance from not NA cells in a raster
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