Hi,

I am trying to create an xy table of the center of random cells in a raster
mask. These cells must occur within a certain distance from xy locations. I
have successfully found 2 ways of doing this, but both run out of memory (R
64-bit version 2.14.0) when using very large datasets. I think I have gone
about this in a backwards manner and assume there is a simpler way to do
this.

The following example works, but when I use my actual datasets and create
lots of overlapping buffers the code runs out of memory. when using the
function extract.

Thanks,
Daisy

rm(list = ls())

#load libraries

library(dismo)
library(raster)

##example data
#load map of land
files<-list.files(path=paste(system.file(package="dismo"),"/ex",sep=""),pattern="grd",full.names=TRUE)
mask <- raster(files[[9]])
#make species data
pts<-randomPoints(mask,2000)
 #extract the unique cell numbers within a 800km buffer of the points,
remove NA cells
#####momory problems#####
z <- extract(mask, pts, buffer=800000,cellnumbers=T)
z2<-as.data.frame(do.call(rbind,z))
z3<-subset(z2, vals == 1, select = cells)
#find the unique cells
z4<-unique(z3[,1])
#get 1000 random cells from the remaining data
cells<-sample(z4, 1000, replace=FALSE)
#find lat and long of center point of cells
xy_locs<-xyFromCell(mask,cells)


-- 
Daisy Englert Duursma
Department of Biological Sciences
Room E8C156
Macquarie University, North Ryde, NSW 2109
Australia

	[[alternative HTML version deleted]]

