2

I got a list of values and I could print them to the Console. It looks like this:

{
    "chlor_a": 0.12718113166405862
  },
  {
    "chlor_a": 0.37072379355468843
  },

How can I export it to my Drive account in csv format?

This is the code so far:

var bo=ee.FeatureCollection('users/broadsky2008/Border');

var chla = ee.ImageCollection("NASA/OCEANDATA/MODIS-Aqua/L3SMI")
.filterDate('2012-7-04', '2018-1-25')
.select('chlor_a');

var reduceR = function(image) {
  return image.set('number',image.reduceRegion({
  reducer: ee.Reducer.mean(),
  geometry: bo.geometry(),
 }));
};

// Map the function over the collection and display the result.
var mChla=chla.map(reduceR);


// Get a list of the numbers.
var numberList = mChla.aggregate_array('number');

print(numberList);

1 Answer 1

3

The argument(s) to set() should be either a key, value pair or a dictionary. Here is your (corrected) example, assuming you've got a geometry called geometry defined somewhere:

var chla = ee.ImageCollection("NASA/OCEANDATA/MODIS-Aqua/L3SMI")
  .filterDate('2018-1-04', '2018-1-25')
  .select('chlor_a');

var reduceR = function(image) {
  return image.set(image.reduceRegion({
    reducer: ee.Reducer.first(),
    geometry: geometry,
 }));
};

var mChla=chla.map(reduceR);

Export.table.toDrive({
  collection: ee.FeatureCollection(mChla), 
  description: 'foo', 
  fileNamePrefix: 'foo', 
  fileFormat: 'CSV', 
  selectors: ['chlor_a']
});
0

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.