Two issues with your script:
1) A single image works best when you use ee.Image
instead of ee.ImageCollection
.
2) You switched up the granule name. The first part is the sensing time and the second the ingestion time. An acquisition taken in 2016 cannot be ingested in 2015. It should be 20150828T110656_20160412T015159_T30SVG
not the other way round.
As a complete script (on EarthEngine):
// not in Collection - switched sensing and acquisition time
// var s2 = ee.Image('COPERNICUS/S2/20160412T015159_20150828T110656_T30SVG');
// in Collection - correct granule
var s2 = ee.Image('COPERNICUS/S2/20150828T110656_20160412T015159_T30SVG');
Map.addLayer(s2, {bands: ['B8', 'B4', 'B3'], max: 4000}, 'S2')
Map.centerObject(s2, 8);
Here's an example that hopefully does something like what you want, but you'll need to modify it to meet your requirements for "manually selected marker points" and Sentinel 2.
In general, do NOT use for-loops or getInfo()
. To be clear, DO NOT USE FOR LOOPS unless you have a very good reason to be doing so. If you don't know, use map()
for all the reasons described here, here, here and here. (And check the same guides for why to NOT use getInfo()
or convert to a list as I've done here.) The reason it's OK to do this here (necessary, in fact) is because Export
is a client side function and you can't use a client function in map()
.
// Get some imagery to play with.
var landsat = ee.ImageCollection("LANDSAT/LC08/C01/T1")
.filterDate('2016-01-01', '2017-01-01');
var composite = ee.Algorithms.Landsat.simpleComposite({
collection: landsat,
asFloat: true
});
var rgbVis = {bands: ["B4", "B3", "B2"], min:0, max: 0.3};
Map.addLayer(composite, rgbVis, "RGB");
// This is a hacky way to get a pixel grid at arbitrary resolution.
var pixels = ee.Image.random().multiply(10000000).toInt32()
.reduceToVectors({
reducer: ee.Reducer.countEvery(),
geometry: Map.getBounds(true),
geometryType: 'bb' ,
eightConnected: false,
scale: 20000,
crs: 'EPSG:4326'
});
Map.addLayer(pixels);
// Only do this is you have a few regions. Not suitable for
// large feature collections.
var pixelsList = pixels.toList(pixels.size());
// This is one of the few places in the EE API where you need
// a for-loop and a getInfo() call. Export is a client function.
for (var i=0; i<pixels.size().getInfo(); i++) {
Export.image.toDrive({
image: composite,
description: 'foo_' + i,
fileNamePrefix: 'foo_' + i,
region: ee.Feature(pixelsList.get(i)).geometry(),
scale: 30,
});
}
If you really need precise control over the export regions, you can make lists of coordinates and turn those into a collection of the ROIs you want to export. All that aside, you still need to click 'Run' on the exports. If you want it completely automated, use the Python API and ee.batch.Export
followed by task.start()
.
Best Answer
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:
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
=):But if you want to change the filter regarding on whether it finds or not images, that would be different.