[GIS] Randomly generate points using weights from raster

qgisrrandomrasterweighted-overlay

I need to randomly generate ~ 40K points throughout my region of interest, but I need to weight the point selection by a set of probability weights, stored as a raster – such that higher probability areas have more of the random points and lower probability areas have fewer points. Additionally, I need to indicate a minimum distance between the points.
I found that I could do this in ArcMap using the "create spatially balanced points" tool in the GeoStatistical Analyst package – but I do not have a license for that package.
Is there a way to do this in QGIS or R?
I found the sp package in R to randomly select points – but I do not see how I can weight that selection given the "type" options.

Any suggestions on how to solve this problem? Other R packages that I should check out?

Best Answer

I don't understand the "minimum distance" thing you mentioned.

Here's how to generate 1000 points uniformly within cells but with the number in each cell weighted by the cell value:

Make a test 3x4 raster with some positive random numbers:

> set.seed(12)
> r = raster(matrix(runif(12),3,4))

Get the cell half-width for later:

> hs = res(r)/2

Now work out which cell each of our 1000 points is going in by sampling from the number of cells (12) with replacement, weighted by the value in the cells:

> ptscell = sample(1:12, 1000, prob=r[], replace=TRUE)

Now find the centre of those 1000 cell numbers:

> centres = xyFromCell(r,ptscell)

And generate random uniform points in the cell by using the centre and the half-width/height from earlier:

> pts = cbind(runif(nrow(centres),centres[,1]-hs[1],centres[,1]+hs[1]),runif(nrow(centres),centres[,2]-hs[2],centres[,2]+hs[2]))

Voila:

> plot(r)
> points(pts)

points weighted by raster value