Distance from not NA cells in a raster

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Distance from not NA cells in a raster

Dave Gregovich
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
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Distance from not NA cells in a raster

Dave Gregovich
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: '[hidden email]'
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]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Distance from not NA cells in a raster

Ben Tupper
In reply to this post by Dave Gregovich
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) <[hidden email]> 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
> [hidden email]
> 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]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo