0

Sorry if this is an silly question, as I am starting to work with GEE.

I am iterating (mapping) over a Sentinel-2 image collection, using different coordinates and dates in each step.

My goal is to download the mean band properties of the available images in each step, but I want to "join" the FeatureCollections obtained in each step to avoid downloading multiple files.

How should I proceed?

Here is some code example:

var S2 = ee.ImageCollection("COPERNICUS/S2");

// List with LAT, LON, and dates

var list = [
[42.454,3.543, '2017-05-23','2017-06-24'],
[42.7,3.8, '2018-04-19','2018-05-20'],
];

var loop = function(point)
{
  var x = point[1];
  var y = point[0];
  var date0 = point[2];
  var date1 = point[3];
  var point = ee.Geometry.Point([x,y]);

  //Filtering
  var S2TemporalFiltered = S2.filterDate(date0,date1);
  var S2SpatialFiltered = S2TemporalFiltered.filterBounds(point);


  //Box coordinates to reduce collection
  var x1 = x - 0.002;
  var x2 = x + 0.002;
  var y1 = y - 0.001;
  var y2 = y + 0.001;
  var box = ee.Geometry.Rectangle(x1,y1,x2,y2);

  //Cutting collection to box
  var S2Clipped = S2SpatialFiltered.map(
    function(img) {return img.clip(box)}
    );

  //Mean values
  var eBox = ee.Feature(box);
  var func = function(image){
    var meanList1 = image.reduceRegion({
      reducer: ee.Reducer.mean(),
      geometry: eBox.geometry(),
  });
    return ee.Feature(null, meanList1);
  };
  var total = S2Clipped.map(func);


//Now I need to add "total" to a "matrix" where 
// band properties will be added in each step of the loop.
//Each line relates to an image

//This next part should be out of the loop, dowloading all images properties 
//at once (instead of having two files, I would have one file with two rows) 

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

};

var a = list.map(loop)
0

Your function(point) does not return a value, therefore you cannot access nor merge the collection outside the function.

Add this at the end of your function(point) to return a value:

return S2Clipped.map(func);

You can then access the featurecollection outside your function and merge them together using:

var a = ee.FeatureCollection(list.map(loop)).flatten()

print(a) 

And export the full colleciton using:

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

link script

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.