I have a list of FeatureCollections that I want to export all at once (instead of writing out the export module multiple times) using Javascript API. I have seen the posts by @Rodrigo E Principe such as here and others like this one showing the use of normal JS loops (admittedly the second link is for exporting to asset).
I am trying to do the exact same thing as the first link, just exporting a FeatureCollection instead of an ImageCollection. However, when I run the code I get no tasks to run nor am I getting any errors. I don't understand what's happening.
Here is my code:
// Make a list of Features.
var features = [
ee.Feature(ee.Geometry.Point(97.58, 24.36), {name: 'sample1'}),
ee.Feature(ee.Geometry.Point(99.45, 20.26), {name: 'sample2'}),
ee.Feature(ee.Geometry.Point(93.24, 21.42), {name: 'sample3'}),
ee.Feature(ee.Geometry.Point(96.13, 24.12), {name: 'sample4'}),
ee.Feature(ee.Geometry.Point(96.88, 22.48), {name: 'sample5'})
];
// Create a FeatureCollection from the list and print it.
var points = ee.FeatureCollection(features);
print(points);
var l8sr = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2015-06-23', '2020-01-31')
.filterBounds(points);
print("Landsat", l8sr)
var index = ee.List.sequence(0,4)
var coords = points.geometry().coordinates()
print('coords', coords)
// do this for each index
var test1 = index.map(function(q){
var sub = l8sr.filterBounds(ee.Geometry.Point(coords.get(q)))
return sub
});
//run test for first one
var firstcoll = ee.ImageCollection(test1.get(0))
var img = firstcoll.first();
var bands = img.bandNames()
//get the value for each band for every image
var loop = index.map(function(ind){
var getvals = function(img1){
var date = img1.date().format('yyyy-MM-dd')
var value = img1.select(bands)
.reduceRegion(ee.Reducer.first(), ee.Geometry.Point(coords.get(ind)))
return ee.Feature(ee.Geometry.Point(coords.get(ind)), {value: value, date: date})
};
var newft = firstcoll.map(getvals);
return(newft);
});
print('loopresult', loop)
print('loop ex', ee.FeatureCollection(loop.get(0)))
// loop on client side
for (var i = 0; i<loop.length;i++) {
var toexport = ee.FeatureCollection(loop.get(i));
var nam = "test_point_" + i
// Export
Export.table.toDrive(
{collection: toexport,
description: nam,
folder: "dissertation",
fileNamePrefix: nam,
selectors: ['B1','B2','B3','B4','B5','B6','B7','B10','B11',
'pixel_qa', 'radsat_qa', 'sr_aerosol']
});
}