dismo::randomPoints: how to get random points that are not NA across a raster stack

99 views
Skip to first unread message

Kaija Gahm

unread,
Jan 11, 2018, 3:27:47 PM1/11/18
to Maxent
Hi there,
I am trying to use the randomPoints function within the dismo package to select random points with a raster stack (9 layers) as a mask. The documentation for randomPoints says that "The points are sampled (without replacement) from the cells that are not 'NA' in raster 'mask'," and it claims that either a Raster Layer or a Raster Stack object can be passed to the `mask` argument.

However, I am finding that while passing a Raster Stack object works for selecting the points, some NA values turn up in layers of the raster stack other than the first layer, which I guess is the one that the function is using as a mask.

Does anyone have any idea how I can select random points such that any cells that are NA in any layer of the raster stack are excluded? That is, select points such that they have valid values across all layers in the stack?

I posted this as a question to stack exchange, if anyone is interested in seeing some more details of my code. Also happy to provide additional information.

Thanks for any ideas you might have.

Adam Smith

unread,
Jan 12, 2018, 10:49:04 AM1/12/18
to Maxent
Hi Kaija,

Do this:
1) Make a raster stack of your rasters
2) Calculate some summary statistic across them that becomes NA is any one of the values in a cell is NA.  For example:
mask <- sum(myStack)
3) Then use this raster to draw random points from using randomPoints().

This method creates a raster with NAs in a cell in which at least one of the component rasters have an NA.  So they should not be included in the randomPoints() draw.

Best,
Adam
Reply all
Reply to author
Forward
0 new messages