I am trying to randomly distribute points in a raster (that has 11 unique values). I followed this posting and was able to recreate it, being partially successful.

As mentioned about, my raster has 11 unique values and I want different number of points randomly placed based on the unique strata. Also, I need different number of points.

So as the posting says,I isolated individual unique layers based on the unique value

raster[raster != 81] = NA # creating a raster with pixels of value 82 and remaining pixels Nodata

Then I used the sampleStratified() function as mentioned int he post

x<-sampleStratified(raster,1 , sp=T)

I want only 1 point to be randomly placed and I get this error

Error: size > 0 is not TRUE
In addition: Warning messages:
1: In .local(x, size, ...) :
fewer samples than requested found for stratum: 81

I don't understand how to rectify this because there are over 2000 pixels in the raster with pixels of value 81. So does this mean that sampleStratified() was not able to place 1 point in any of the >2000 pixels present? How do I rectify this error.

  • I can't reproduce your error, not with a raster full of NAs or a raster full of zeroes, or negative numbers, or all TRUE or all FALSE. Could you show us summary or table on your raster values? – Spacedman May 30 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.