0

I want to read an imageCollection, reduce all images in the collection by the region. and save the result.

However, when I save the result, the properties of the feature Collection is gone. It does not get saved.

Any suggestion?

// Load four 2012 NAIP quarter quads, different locations.
var naip2012 = ee.ImageCollection('USDA/NAIP/DOQQ')
                .filterBounds(ee.Geometry.Rectangle(-71.17965, 42.35125, -71.08824, 42.40584))
                .filterDate('2012-01-01', '2012-12-31');

var reduced = naip2012.map(function(image){
  return image.reduceRegions({
    collection:ee.Feature(ee.Geometry.Rectangle(-71.17965, 42.35125, -71.08824, 42.40584)), 
    reducer:ee.Reducer.mean(), 
    scale: 30
  });
});

reduced = reduced.flatten();
print(reduced);

Export.table.toDrive({
  collection: reduced,
  description:'properties_gone_by_saving',
  fileFormat: 'CSV'
});

1 Answer 1

0

Convert the reduced to a dictionary. The result of that would be the properties. Add the dictionary to all images of the imageCollection.

Export the result:

// Load four 2012 NAIP quarter quads, different locations.
var naip2012 = ee.ImageCollection('USDA/NAIP/DOQQ')
                .filterBounds(ee.Geometry.Rectangle(-71.17965, 42.35125, -71.08824, 42.40584))
                .filterDate('2012-01-01', '2012-12-31');

var reduced = naip2012.map(function(image){
  return image.reduceRegions({
    collection:ee.Feature(ee.Geometry.Rectangle(-71.17965, 42.35125, -71.08824, 42.40584)), 
    reducer:ee.Reducer.mean(), 
    scale: 30
  });
});

var reduced_flat = reduced.flatten();

Export.table.toDrive({
  collection: reduced_flat,
  description:'properties_gone_by_saving',
  fileFormat: 'CSV'
});

/////// Solution here //
reduced = reduced.toDictionary();
reduced_flat = reduced_flat.map(function(im){return(im.set(reduced))}); 

print(reduced_flat);

Export.table.toDrive({
  collection: reduced_flat,
  description:'properties_not_gone',
  fileFormat: 'CSV'
});

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.