Google Earth Engine – How to Export Tables with Variable Name in Google Earth Engine

exportfeature-collectiongoogle-earth-enginegoogle-earth-engine-javascript-api

I am using 'featureCollection.features.forEach()' inorder to loop over a featurecollection and make some changes to each feature.
after each iteration I want to export a CSV file.
I want to name each file with a specific property of the feature ('my_index') but I am getting this error: feature.get is not a function.

  sheds.select(['my_index']).evaluate(function (featureCollection) {
        featureCollection.features.forEach(function (feature) {
    
        var file_name = feature.get('grdc_no');
    
        Export.table.toDrive({  
        collection: table_precip,
        description: file_name,    //get name of the file from the property 'my_index'
        folder: 'rain test',
        fileFormat: 'CSV',
        });
      });
    });

Best Answer

You've already extracted all the data from Earth Engine using the evaluate function, so you can no longer use Earth Engine functions on the results. The feature you have inside the function is going to have a properties dictionary in it, and the variable you're trying to access will be inside that. So you'd access it with something like this instead of using get():

feature['properties']['grdc_no']

But you won't then be able to export the results, since they're in your browser and no longer in Earth Engine.

If the bigger picture of what you're trying to do is to export each feature to its own file, then I think it would be easier to just split them up once you've downloaded all of them.