Sunday, 10 May 2015

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 = "+")


first plot


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 = "+")

second plot


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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...