I have some areas defined by square polygons and saved as tables in my GEE assets. I want to read them one by one, enlarge them and save the enlarged box to my assets again. I wrote below code but it doesn't do anything:

var Tables = ee.List(ee.data.getList({id:'myassets/boxes'}))
var l = Tables.length()
for(var i=0; i<l; i++){
  var box = Tables.get(i)
  var g = b.geometry()
  var box2 = g.buffer(1000).bounds();
    collection: box2,
    assetId: 'Box2_'+string(i)

What is wrong with it?

1 Answer 1


You are mixing client-side with server-side code. See the GEE help for that. Hopefully, this will show you how to work with a client-side for loop to export multiple featureCollections. As your asset is not shared, I am unsure if the code will work for the buffer you're trying to make.

// get the list of features (client side)
var Tables = ee.data.getList({id:'myassets/boxes'});
var l = Tables.length;
// tranform into a list of feature collections (server-side)
var feats = ee.List(Tables.map(function(fc){
  return ee.FeatureCollection(fc.id);

// do a client-side mapping over the features to export each individual featurecollection
for(var i = 0; i < l; i++){
  var box = feats.get(i); // get fc at certain index
  var fc = ee.FeatureCollection(box); // cast to fc
  var g = fc.geometry();// get the geometry of the fc (depends on your asset if this works)
  // apply the buffer
  var box2 = g.buffer(1000).bounds();
  // cast to fc to export
  var fcExport = ee.FeatureCollection(ee.Feature(box2)); 
          // .set() possibly properties you want to keep on the feature
  print('printing to see if for loop works', fcExport);
    collection: fcExport,
    assetId: 'Box2_'+String(i)

  • Thank you very much, it worked. You are right and my understanding from client- and server-side things in GEE is low, but the documentation is also not sufficient and incomplete. My understanding from your code is that you first get the list in client, then convert it to a server-side list, then loop over it and do all the GEE operations such as geometry(), buffer(), bounds(), and export on that. This is because the GEE operations should be run on server-side objects, right?
    – Shahriar49
    Commented Oct 4, 2019 at 14:25
  • But why to get a list in client and convert it again to a server-side object at the start? The assets are already on server.
    – Shahriar49
    Commented Oct 4, 2019 at 14:26
  • All 'red' function retrieve things from the server on the client side. You were trying to do a client-side for loop, so you will need a client side variable length (l in your case).
    – Kuik
    Commented Oct 4, 2019 at 18:50
  • Variable length (l) is fetched by var l=Tables.length, right? Why we need to create again the server-side feature collection 'feats' ? Why can't we read the assets directly in the for loop?
    – Shahriar49
    Commented Oct 4, 2019 at 19:54

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.