I have a function calculateForestLoss_plantspecies
that returns a FeatureCollection. I was trying to modify the function to use the .map
to combine multiple feature collections. However, due to some reason, the code below doesn't work.
var unique_values = ee.List([181, 182, 183]);
function calculateForestLoss_plantspecies(input, geometry, val, savefilename) {
// var area == /*.....*/
return area
}
// Define the function that calculates forest loss for a single value
function calculateForestLoss_plantspecies_for_value(val) {
var fc = calculateForestLoss_plantspecies(FL_att_to_old_plantations_species, geometry, val, savefilename);
return fc; // select the properties you want to keep
}
// Apply the function to each value in the list using .map()
var fc_list = unique_values.map(function(val) {
return calculateForestLoss_plantspecies_for_value(val);
});
// Merge the resulting feature collections
initial_var = ee.FeatureCollection(fc_list).flatten();
On the other hand, if I run it with merge, the code works perfectly.
initial_var = calculateForestLoss_plantspecies_for_value(181)
.merge(calculateForestLoss_plantspecies_for_value(182))
.merge(calculateForestLoss_plantspecies_for_value(74))
print(initial_var)
Note: Feature collection can have different properties, sometimes non-overlapping with other features.
Can someone tell me why my .map
code is not working? I have been searching on the internet for quite some time, but have yet to find a solution.