I'm trying to collect a set of sample points from all the images in a collection. However instead of outputting a Feature Collection that consists of a group of Features with the training data as properties, I get a Feature Collection that contains another nested Feature Collection for each image I process, and cannot tell if these contain the training data I want.

How can I output the data as one featureCollection containing nothing but features? Do I have to use the .iterate()? From the examples I am unsure how to apply this for my purpose.

    // Create Example Collection
var collection =  ee.ImageCollection("LANDSAT/LT05/C01/T1_TOA")
  .filterDate('2001-01-01', '2001-12-31')
  .filterMetadata('CLOUD_COVER', 'equals', 0);


// function for sampling training data
function sampleImage(image) {
    var bands = ['B1', 'B2', 'B3'];
    var param = {region: clust, scale: 30, numPixels: 500};
    var SamPix = image.select(bands).sample(param);
    return SamPix;
var training = collection.map(sampleImage);
print(training, "sample points"); 

1 Answer 1


You should use flatten() to get the features from the feature collection of a collection:

var training = collection.map(sampleImage).flatten();

Link code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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