I am trying to write a function which will create a dictionary from an image collection using Sentinel 2 data which will contain label/value pairs where the label comes from the MGRS_TILE property of the image and the value will contain a list of all the images with the same MGRS_TILE id. The label values must be distinct.I want the output to be like this: {'label' : 'tileid1', 'values':[ image1, image2 ...] 'label' : 'tileid2', 'values':[ image3, image4 ...]}
Below is my code: interestImageCollection is my filtered imageCollection object tileIDS is a ee.List type object containg all of the distinct tile ids and field is the name of the image property of my interest which in this case is '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;
};
Unfortunately the above function gives me this result: {'label' : 'tileid1', 'values':[], 'label' : 'tileid2', 'values':[]}