I am a pretty new user to Earth Engine, and I am trying to map over a list in order to use the numbers inside as indices. As a quick example, in R this would be
for (i in 1:10){print i}
In Earth Engine, doing this separately works beautifully. Here, "points" is a FeatureCollection made up of 10 points, and my goal is to filter the "l8sr" ImageCollection to only give me the images that pertain to point #2. Then, I get mean NDVI for the time series.
var coords = points.geometry().coordinates()
print('coords', coords)
var onepoint = ee.Geometry.Point(coords.get(2)) //for example
print(onepoint)
var test = l8sr.filterBounds(onepoint)
print('test', test)
print(ui.Chart.image.series(test, onepoint, ee.Reducer.mean(), 30))
BUT, when I try to map this over all 10 points in "coords", I get a list of 10 empty ImageCollections (I can't print to a chart because these are undefined). Why is this?
Here is reproducible code:
// Make a list of Features.
var features = [
ee.Feature(ee.Geometry.Point(97.58, 24.36), {name: 'sample1'}),
ee.Feature(ee.Geometry.Point(99.45, 20.26), {name: 'sample2'}),
ee.Feature(ee.Geometry.Point(93.24, 21.42), {name: 'sample3'}),
ee.Feature(ee.Geometry.Point(96.13, 24.12), {name: 'sample4'}),
ee.Feature(ee.Geometry.Point(96.88, 22.48), {name: 'sample5'})
];
// Create a FeatureCollection from the list and print it.
var points = ee.FeatureCollection(features);
print(points);
var l8sr = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2015-06-23', '2020-01-31')
.filterBounds(points)
print("Landsat", l8sr)
//this works (down to /$/$)
var coords = points.geometry().coordinates()
print('coords', coords)
var onepoint = ee.Geometry.Point(coords.get(2))
print(onepoint)
var newt = l8sr.filterBounds(onepoint)
print('newt', newt)
print(ui.Chart.image.series(newt, onepoint, ee.Reducer.mean(), 30))
// /$/$ /////////////
// this doesn't work
var ser = ee.List.sequence(0,4)
print(ser)
var test1 = ser.map(function(q){
var sub = l8sr.filterBounds(ee.Geometry.Point(coords.get(q)))
return sub
//return ui.Chart.image.series(sub, point_a, ee.Reducer.mean(), 30)
})
// test1 is a list of ImageCollections, but each one has no actual bands.
print(test1)