我正在尝试编写一个函数,该函数将使用 Sentinel 2 数据从图像集合中创建一个字典,该字典将包含标签/值对,其中标签来自图像的 MGRS_TILE 属性,值将包含所有图像的列表相同的 MGRS_TILE id。标签值必须不同。我希望输出是这样的: {'label' : 'tileid1', 'values':[ image1, image2 ...] 'label' : 'tileid2', 'values':[图像3,图像4 ...]}
下面是我的代码:interestImageCollection 是我过滤后的 imageCollection 对象 tileIDS 是一个 ee.List 类型对象,包含所有不同的 tile id,字段是我感兴趣的图像属性的名称,在本例中为“MGRS_TILE”。
var build_selectZT = function(interestImageCollection, tileIDS, field){
//this line returns a list which contains the unique tile ids thanks to the keys function
//var field_list = ee.Dictionary(interestImageCollection.aggregate_histogram(field)).keys();
//.map must always return something
var a = tileIDS.map(function(tileId) {
var partialList=ee.List([]);
var partialImage = interestImageCollection.map(function(image){
return ee.Algorithms.If(ee.Image(image).get(field)==tileId, image, null);
});
partialList.add(partialImage);
return ee.Dictionary({'label': tileId, 'value': partialList});
}).getInfo();
return a;
};
不幸的是,上面的函数给了我这个结果: {'label' : 'tileid1', 'values':[], 'label' : 'tileid2', 'values':[]}