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?
No comments:
Post a Comment