# R raster - take stratified sample

This question was posted in stackexchange, where there were no views/comments/answers.

I have a raster file and would like to take a stratified sample.

``````library(raster)
f = system.file("external/test.grd", package="raster")
r = raster(f)
r[r < 500] = 1
r[r >=500 & r <=1200] = 2
r[r > 1200] = 3

plot(r, legend = F)
s = sampleStratified(r, 20, sp = T)
points(s, pch = "+")
`````` This has 2 problems for my intended use. First, the same amount of points are assigned to each area, although the surfaces differ a lot. Second, the points are clustered, and I would like to see a minimum distance between them.

I can solve the first problem by isolating individual layers and assigning a number of samples that is proportional to the area:

``````r[r != 1] = NA
plot(r, legend = F)
s = sampleStratified(r, 20, sp = T)
points(s, pch = "+")
`````` But that does not solve the clustering problem.

How can I use raster to take a stratified sample that is proportional to the areas and in which some distance between sampling points is maintained?

• These points are not clustered. They are realisations of a Poisson point process with constant intensity conditioned on the count. Each point is independent of all the other points, so there's no clustering tendency. It sounds like you want to create points from an inhibitory point process, which you can do with the theory and practice of the `spatstat` package in a dozen different ways. – Spacedman Nov 29 '18 at 8:45
• Thanks! I'd be happy with a pointer to one of the dozen. – user39444 Nov 29 '18 at 9:34
• The `rStrauss` function: rdocumentation.org/packages/spatstat/versions/1.57-1/topics/… note that it might be impossible to put N points in a window of area A subject to a minimum distance constraint, and even when not impossible it can be computationally hard. – Spacedman Nov 29 '18 at 10:45