12

I am trying to export each image in a filtered stack of Sentinel-1 images and cannot seem to get it right.

Think link suggests using imageCollection.map() and a custom function (such as a geometric clip).

// Create a geometry representing an export region.
var roi = ee.Geometry.Rectangle([-63.0, 9.2, -63.1, 9.3]);


// Load the Sentinel-1 ImageCollection.
var sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD');


// Filter by metadata properties.
var IW_H = sentinel1
  // Filter to get images with VV and VH dual polarization.
  .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
  .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
  // Filter to get images collected in interferometric wide swath mode.
  .filter(ee.Filter.eq('instrumentMode', 'IW'))
  // Filter IWs to get High res.
  .filter(ee.Filter.eq('resolution', 'H'))
  // Filter IW-Highs to get 10m res
  .filter(ee.Filter.eq('resolution_meters', 10));


// Filter to get images from different look angles 
var DescCollection = IW_H.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'));


var ClipFunc = function(iImage, geom) {
  var iClip = clip(iImage, geom);
  return(iClip);
};


imageCollection.map(ClipFunc(DescCollection, roi));

2 Answers 2

30

Export.image.toDrive is a client-side function, and you cannot call it from a server-side function (the one you are mapping over), so you have to do it all in the client side. I have a repo where you can find a bunch of useful functions: https://github.com/fitoprincipe/geetools-code-editor There is a function to export all images from an ImageCollection to the Drive cloud.

var batch = require('users/fitoprincipe/geetools:batch')

// Create a geometry representing an export region.
var roi = ee.Geometry.Rectangle([-63.0, 9.2, -63.1, 9.3]);


// Load the Sentinel-1 ImageCollection.
var sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD');


// Filter by metadata properties.
var IW_H = sentinel1
  // Filter to get images with VV and VH dual polarization.
  .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
  .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
  // Filter to get images collected in interferometric wide swath mode.
  .filter(ee.Filter.eq('instrumentMode', 'IW'))
  // Filter IWs to get High res.
  .filter(ee.Filter.eq('resolution', 'H'))
  // Filter IW-Highs to get 10m res
  .filter(ee.Filter.eq('resolution_meters', 10));


// Filter to get images from different look angles 
var DescCollection = IW_H.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'));

batch.Download.ImageCollection.toDrive(DescCollection, 'Folder', 
                {scale: 10, 
                 region: roi.getInfo()["coordinates"], 
                 type: 'float'})

You can find the complete code in here and the documentation here

11
  • 2
    Thanks for the response. I've seen this code and attempted it. I'm not very knowledgeable with GEE or javascript. My Chrome browser is going unresponsive and asks to be killed. I'm not sure if it's running (and grinding down my machine) or if something is amiss. I will try with a very limited collection as a test. cheers Commented Jul 19, 2017 at 21:14
  • @ThrushJacket I use mainly the Python API, so I am not sure if this works properly, I'll check it right now. I think the region parameter may cause the error Commented Jul 19, 2017 at 22:08
  • @ThrushJacket I tested it, works fine just as it is. Try with less images, as it is a client side, it can hang your browser. Commented Jul 19, 2017 at 22:21
  • 3
    If your export image gets too large GEE will export it in separate shards you can merge after downloading.
    – Kersten
    Commented Jul 20, 2017 at 12:00
  • 1
    You are importing the repository into tools variable but trying to use batch.. see: code.earthengine.google.com/dcee89acbe86bca49ce72605a9f5a7fe (line 90 makes the difference) Commented Jul 16, 2019 at 11:41
0

I was unable to apply Rodrigo E. Principe's algorithm. The GEE states the following phrase:

"Cannot read property 'toDrive' of undefined"

I tried to run the algorithm for two different imageCollections, but the same error occured in both. The first was Rodrigo's Dataset (SENTINEL-1 data), exactly as stated in his answer above. The second trial was over precipitation data. This later algorithm is presented below.

 var batch = require('users/fitoprincipe/geetools:batch');
 var Municipios =  ee.FeatureCollection("ft:1YvIAGUsonY9NVnSJETwkWjj_UO_Db0zqSHx2WHIs");

print(Municipios.limit(20), 'Municipios 500x500m2');


var roi = Municipios.geometry().dissolve().bounds();

print(roi, 'roi');

print(roi.getInfo()["coordinates"], 'get info coordinates from roi');

// Display the sample region.
Map.centerObject(roi, 5);
Map.addLayer(ee.Image().paint(roi, 0, 2), {}, 'ROI');



// Load a pre-computed Landsat composite for input.
var precipitation = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
    .filterDate('1981-01-01', '2019-12-31')
    .select('precipitation')
    .filterBounds(Municipios.geometry().dissolve().bounds())
    .map(function(image) {
      // Data to .
      return image.set('system:time_start', image.get('system:time_start'));
    });

Map.addLayer(precipitation, {'bands': ['precipitation'], min:0, max:2000}, 'collection');




batch.ImageCollection.toDrive(precipitation, 
                'Precipitation_daily_data', 
                {scale: 1000, 
                 maxPixels:5000000000,
                 region: roi.getInfo()["coordinates"], 
                 type: 'float'})

I would like to state that I paid attention to the directory into which the dataset would be downloaded in my Google Drive ('Precipitation_daily_data'), so to garantee beforehand that it would exist, as states in the batch manual cited by Rodrigo.

2
  • Apparently, the error appeared due to a misuse of the property Download from the batch object. I am somehow managing to operate the precipitation dataset by replacing "batch.ImageCollection.toDrive" to "batch.Download.ImageCollection.toDrive". Commented Apr 17, 2019 at 13:13
  • sorry Philipe and all who had the same problem. I didn't see this comment before. I've now corrected the answer, you were right about the code. Commented Jul 15, 2019 at 13:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.