In the first (working) example, the entire analysis is done client-side.
In the second (non-working) example, you are mixing a client-side Javascript function .concat()
with a server-side Earth Engine ee.Number()
object. That is not allowed. See https://developers.google.com/earth-engine/client_server for more details.
From the code supplied, it is not clear what your larger objective is. Could you provide more details on what you are trying to do, and potentially include the function that you mentioned as well?
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
Collections aren't designed for random access; any method you use to get there will severely limit the scalability of your code. That said, you can get to positional chunks by converting to a list, since toList has an offset argument.
A more scalable solution, if you don't mind them being non-contiguous, is to assign a random number to each feature and then iteratively filter to a subset that's approximately 500 items:
However, if you can explain why you want batches in the first place, there's almost certainly a better answer.