2

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
  • 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, 2018 at 13:05
  • 2
    stratifiedSample() is a good solution. If it times out, then export the table. Dec 18, 2018 at 15:18

1 Answer 1

2

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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