Lets say I have a region of mangrove forests (from a classified Landsat image) and I mask out all non mangrove pixels. I view this as a layer on the map and it shows the mangrove forests on the map hugging the coastline. Next, lets say I want to take a random sample of these mangrove pixels. As far as I can tell, this isn't possible, as when setting the parameters for a random sample, the 'whole image footprint' is considered, therefore giving most of the random samples as masked pixels. How can I set masked pixels as noData so when doing a random sample for a 'non-square' image that only the unmasked pixels are sampled. I've included a picture for clarity. Essentially I want the random samples to fall only within the mangrove forest, no for the 'whole image footprint'. I could do a stratified random sampling approach, whereby the sample points only fall within a class of my choosing, but I'm doing this for the whole of Indonesia, which returns a timeout. enter image description here

  • 2
    Could you add the part of the code to get the mangrove image and what you have tried so far to get the random samples? Masked pixels are actually noData pixels in the GEE, so setting pixel values to 'noData' is definitively not the solution. – Kuik Dec 16 '18 at 13:05
  • 1
    stratifiedSample() is a good solution. If it times out, then export the table. – Nicholas Clinton Dec 18 '18 at 15:18

As Nicholas pointed out, stratifiedSample will do this. It skips masked pixels. And if you get a timeout, generate the collection as an Export, where you get more time.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.