Learn R Programming

raptr (version 0.0.3)

randomPoints: Sample random points from a RasterLayer

Description

This function generates random points in a RasterLayer object.

Usage

randomPoints(mask, n, prob = FALSE)

Arguments

mask

RasterLayer object

n

integer number of points to sample

prob

logical should the raster values be used as weights? Defaults to FALSE.

Value

codematrix with x-coordinates, y-coordinates, and cell values.

See Also

This function is similar to dismo::randomPoints.

Examples

Run this code
# NOT RUN {
# simulate data
sim_pus <- sim.pus(225L)
sim_spp <- sim.species(sim_pus, model='normal', n=1, res=0.25)
# generate points
pts1 <- randomPoints(sim_spp, n=5)
pts2 <- randomPoints(sim_spp, n=5, prob=TRUE)
# plot points
plot(sim_spp)
points(pts1, col='red')
points(pts2, col='black')
# }

Run the code above in your browser using DataLab