1

I have some troubles with the sample method from Google Earth Engine. On some images, it returns an empty feature collection (0 element).

Why this is happening and how do I deal with that ?

It's problematic to train a model on an empty dataset...

Here one illustration:

// Example on two images : one working, not the other
var image_ok = ee.Image("COPERNICUS/S2/20150627T102531_20160606T223605_T31RFN");
var image_empty = ee.Image("COPERNICUS/S2/20151228T002843_20151228T085259_T54HYD");
var VisImg = {"opacity":1,"bands":["B4","B3","B2"],"min":293.6805388296989,"max":2220.5270083401124,"gamma":1};

// Sampling
var training_ok = image_ok.sample({numPixels:1000});
var training_empty = image_empty.sample({numPixels:1000});

// Display
print("Ok: ", training_ok);
print("Empty: ", training_empty);

Map.addLayer(image_empty, VisImg, "Image empty");
Map.addLayer(image_ok, VisImg, "Image ok");
Map.centerObject(image_empty);
1

The "empty" image contains QA bands that are completely masked out. You can avoid the empty sample by first selecting the bands that have valid data. For example:

var training_empty = image_empty
  .select([
    'B1',
    'B2',
    'B3',
    'B4',
    'B5',
    'B6',
    'B7',
    'B8',
    'B8A',
    'B9',
    'B10',
    'B11',
    'B12',
    // 'QA10',
    // 'QA20',
    // 'QA60',
  ])
  .sample({numPixels:1000});

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.