3

My goal is to export a large mosaic into tiles defined by individual features in a vector grid (FeatureCollection).

GEE debugging guide states that

Export is a client-side function and won't work in mapped functions.

But when I use client-side loop the whole thing freezes for a long time due a to multiple .getInfo() requests:

// vector_grid is a FeatureCollection with 'tile_id' attribute

var tile_list = vector_grid.getInfo()["tile_id"];

for (var i in tile_list) {
  var tile = ee.Feature(tile_list[i]);
  var tile_id = feat.get("tile_id").getInfo().toString();
  var tile_geom = tile.geometry();

  Export.image.toDrive({
    image: mosaic,
    folder: 'export_path',
    fileNamePrefix: tile_id,
    region: tile_geom,
  });
}

The question is:

Is it possible to do a batch export defined by FeatureCollection in a more rational way within the JavaScript API?

2

If you want to get some information from the tiles to parse to the Export function, you will need getInfo. Alternatively, you could make some "fake" id in the client side (like using i directly).

I think you could get rid of 1 getInfo, I've been doing this in the Python API, and haven't test it in JS, so the following code has not been tested, but you can try it:

var tile_list = vector_grid.toList(vector_grid.size())

var i = 0;
while (i < 1e13) {
  try {
    var tile = ee.Feature(tile_list.get(i));
    var tile_id = tile.get("tile_id").getInfo().toString();
    var tile_geom = tile.geometry();

    Export.image.toDrive({
      image: mosaic,
      folder: 'export_path',
      fileNamePrefix: tile_id,
      region: tile_geom,
    });

    i++  
  } catch (err) {
    break;
  }
}

Note: for the pythonistas, I use while True:, but I couldn't find an equivalent in JS

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.