I want to export Sentinel-2 mosaics for rectangular ROIs. For this, I intend to use a script following this example: https://code.earthengine.google.com/ce1a151ce06497b20cf1793715cb0120

However, whenever I want to run the export task in the "Tasks" manager, I receive the following error after some time: "Error: Export region contains no valid (un-masked) pixels."

This leaves two questions:

1) Why are there no images for the right half of the ROI? The ImageCollection actually contains 9 images. Is that a Sentinel-2 inherent problem?

2) How can I deal with this situation when automated exporting is the goal? I can imagine two general options: a) Export the image anyway (e.g. with the non-covered pixels set to NaN) - but how will GEE let me do this? b) Apply a check if such "empty" pixels are contained in my mosaic image. (Unfortunately, I have no idea how to achieve this.)

1 Answer 1


1st: The exact code you posted (https://code.earthengine.google.com/ce1a151ce06497b20cf1793715cb0120) did export the image correctly. So the error cannot be reproduced. May be, you changed the 'ROI' to a place where the filtered collection had no images.

2nd: There are no images because you filtered by cloud percentage, and so, it found images that suited the condition only in the left part of the ROI. If you comment like:

//.filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE', 5))

you'll see that there are more images and you get the whole ROI (of course you get a part of the image plenty of clouds).

3rd: if automated exporting is your goal, maybe you should migrate to Python, but if you don't mind clicking the run button over and over, this would be one approach to download images only if the filtered collection has images (don't blame me on the getInfo =):

//Define date range
var startDate = ee.Date.fromYMD(2017,7,1);
var endDate = ee.Date.fromYMD(2017,7,31);

//Load Sentinel-2 image collections
var coll_s2 = ee.ImageCollection("COPERNICUS/S2");

//Filter Sentinel-2 collection for ROI and cloud-coverage.
//Keep only images with less than 5% clouds
var coll_s2_filtered = coll_s2.filterDate(startDate, endDate)
                              .filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE', 5))

// Define the FeatureCollection!
var fc = ee.FeatureCollection(LIST_OF_POINT_FEATURES)

// Iterate over the FeatureCollection to create a List
// with images where there is data avialable
var listn = ee.List(fc.iterate(function(elem, ini){
  var rectangle = ee.Feature(elem.buffer(20000).bounds());
  var roi = rectangle.geometry();
  var col = coll_s2_filtered.filterBounds(roi);
  return ee.Algorithms.If(col.size(), 
}, ee.List([])))

listn = ee.List(listn)


// As Export is a Client-side function, you have to iterate the list
// in a client-side way

for (var n = 0; n<listn.size().getInfo(); n++) {
  var i = ee.Image(listn.get(n))
    image: i,
    description: 'image_'+n.toString(),
    scale: 10,
    folder: "tests",
    region: i.geometry()

But if you want to change the filter regarding on whether it finds or not images, that would be different.

  • You are right! When I just clicked my own link and ran the code again it DID work. But believe me: I tried all afternoon yesterday and the exact same code did NOT work then. Maybe it had to do with cache issues...
    – Michael
    Commented Oct 27, 2017 at 7:24
  • The problem is highlighted exactly here: code.earthengine.google.com/a08f7f19940b134575b173a87d1e3cbc. If you comment the first line that imports the fusion table and uncomment the manual list-of-markers, export works. With the feature collection, it doesn't work. Although in both cases I am only processing 3 marker-features. I am really not able to see the difference...
    – Michael
    Commented Oct 27, 2017 at 14:16
  • I don't have permission for reading the fusion table. Is it composed of point features? what's the error? If you give me access I could see.. fitoprincipe82 at gmail Commented Oct 27, 2017 at 14:45
  • I think I have made it accessible to others now, but just to be sure i have invited you via your email address.
    – Michael
    Commented Nov 2, 2017 at 13:19
  • yes, I got it, but it is too big and crashes.. you may have to filter the collection a little bit. I'll try to do that later Commented Nov 2, 2017 at 15:04

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.