17

My goal is to store different exports from Earth Engine projects in separate subfolders of a main GEE_export folder on my Google Drive. I'm using Export.image.toDrive:

Export.image.toDrive({
    image: export_img,
    folder: export_path,
    fileNamePrefix: filename,
});

However, if I pass a path like GEE_export/subdir or GEE_export\subdir or even GEE_export\\subdir it just creates a folder with a corresponding name in my Drive root folder.

What is wrong?

1
  • 2
    Same mistake for me. There is no documentation on the web about this. Very uncomfortable. Does anyone have a solution to solve this issue ? Thibault Feb 27, 2020 at 9:25

2 Answers 2

2

Export to a Drive folder in Earth Engine is really not documented well (at all). Here's how it works:

If there already is a folder with the specified name in Drive, it will export to there. For this it doesn't matter if the folder name specified is in a subdirectory.

Export.image.toDrive({
    image: export_img,
    folder: "dir",
    fileNamePrefix: filename,
});

This will export to /subdir/dir. If no folder called dir exists, a new folder with that name will be created at root (So /dir).

I don't know for sure what happens when there are two folders with the same name. As far as I could tell the file will be put into the folder which was last modified, but I am not entirely sure.

How it is right now, it is not possible to give a path to which Earth Engine should export the file.

1
  • 1
    Not sure why this got down voted. Best I can tell this is actually what happens. Best advice seems to be make a unique folder name and use that for the folder arg. Sep 30, 2020 at 17:34
-2

I share an example script from my repository, which should give you some inspiration as to how you can automate/concatenate the file/folder naming process. In this example, I have 3 images and 10 regions, and my objective is to do the following; clip each image to each of the 10 regions, reclassify them and export them to Google Drive.

Hopefully you can understand it, and adapt it for your purposes. Specifically, you can take direction from my code and modify your script in the export parameters:'folder'. Feel free to post your code here so the community can view/reproduce/comment on it.

As a closing note, when you are exporting images from GEE, you should always specify the arguments 'region' and 'scale'. In some cases, if you do not specify, region, the export's extent will default to the extent in your view-port (i.e. the map viewer in GEE code editor).

Disclaimer: there may be many other methods to achieve your goals that are superior to mine, but this is the only one that I know of at the moment. Hope this helps.

Warmest regards,

J Johanness

//  Load vector boundary
var boundary = ee.FeatureCollection('XXX');

//  Define start and end value for vector layer attribute 'name-of-attribute'
var start_region = 1;
var end_region = 10; // E.g. if my ee.FeatureCollection only has 10 features

//  Load images
var image0 = ee.Image('XXX');
var image1 = ee.Image('XXX');
var image2 = ee.Image('XXX');

//  Prepare image reclassification codes
var oldgroup = ee.List([0,10,11,12,20,21,22]);
var newgroup = ee.List([0,0,1,1,0,1,1]);

//  Perform 'loop' operation
var i;
  for (i=0;i<=2;i++){
    //  This creates an image stack
    var imagestack = ee.List([image1,image2,image3]);
    var year_dict = ee.Dictionary({
      '0':'image1',
      '1':'image2',
      '2':'image3'
    });
    var year_string = year_dict.get(ee.Number(i).format()).getInfo();
var j;
  for (j=start_region;j<=end_region;j++){
    var region = boundary.filter(ee.Filter.eq('name-of-attribute', j));
    var imagexregion = ee.Image(imagestack.get(i))
    .clip(region).remap(oldgroup,newgroup);
    var region_string = String(j);
Export.image.toDrive({
  image:imagexregion.uint8(),
  description:'esa-'+region_string+'-'+year_string, // This is the part you are asking about.
  folder:'esa-loop-test',
  region:region,
  scale:300, // spatial resolution of my dataset
  crs:'EPSG:4326',
  maxPixels:1e13,
  fileFormat:'GeoTIFF'});
  }
}
1
  • Would have been sufficient to reply that creating a single folder in the root directory of Google Drive by concatenating all the fields of the desired naming convention is the best option you've come up with. As provided, this code snippet produces the same outcome as the OP (just with slashes replaced by hyphens).
    – David Diaz
    Jul 26, 2020 at 20:56

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.