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()
.
Change points
to be a list, rather than a MultiPoint Geometry. There is no map function for MultiPoint Geometries, but there is one for lists:
var points = /* color: #d63000 */ee.List(
[[1.3634359574461996, 31.636034304440155],
[3.6046468949461996, 31.148372138748694],
[-0.9656656050538004, 29.172742327143503],
[2.8575765824461996, 29.172742327143503],
[0.7042562699461996, 30.506858885801098],
[-1.6248452925538004, 30.884738935660458],
[-3.8221109175538004, 27.62655429384725],
[2.2862875199461996, 25.781544169671214]]);
// var mp = ee.FeatureCollection(points)
// print(mp)
var mp = ee.FeatureCollection(points.map(function(p){
var point = ee.Feature(ee.Geometry.Point(p), {})
return point
}))
print(mp)
A suggested edit to this question also points out that you may use the .coordinates()
method to cast your coordinates to a mappable form:
var points = /* color: #d63000 */ee.Geometry.MultiPoint(
[[1.3634359574461996, 31.636034304440155],
[3.6046468949461996, 31.148372138748694],
[-0.9656656050538004, 29.172742327143503],
[2.8575765824461996, 29.172742327143503],
[0.7042562699461996, 30.506858885801098],
[-1.6248452925538004, 30.884738935660458],
[-3.8221109175538004, 27.62655429384725],
[2.2862875199461996, 25.781544169671214]]);
// var mp = ee.FeatureCollection(points)
// print(mp)
var mp = ee.FeatureCollection(points.coordinates().map(function(p){
var point = ee.Feature(ee.Geometry.Point(p), {})
return point
}))
print(mp)
Best Answer
Here is a toy example of exploding multi-geometry features in a feature collection into individual features (in a feature collection).
Code Editor script
Note: this solution relies on the
.toList()
method, which is resource intensive, so may not work for large feature collections or features that include many coordinates (large/complex/precise).