Geographic Information Systems Asked on December 12, 2020
I’m trying to transform client-side functions to server function in GEE. However, I cannot obtain the desired result for the function named "add to list". The problem is that I want to add new elements from a list to another list one by one. But the result that I’m obtaining is the first list and then the other one.
https://code.earthengine.google.com/01bddb3d2f7c2eb87d30496646c06382
// Add fixed vallues to a list CLIENT SIDE
var addToList_ClientSide = function(list, season){
var ini_season = season[0]
var end_season = season[1]
var years_seq = [];
for (var i = 0; i < list.length; i++){
var el = [list[i], ini_season, end_season]
years_seq.push(el)
}
return years_seq
};
// Add fixed vallues to a list SERVER SIDE
var addToList_ServerSide = function(list, season){
var ini_season = season.get(0)
var end_season = season.get(1)
var years_seq = ee.List.sequence(list.get(0), list.get(-1))
var el = ee.List([ini_season, end_season])
return years_seq.add(el)
};
The direct correspondence to your for
loop is a map
over a number sequence:
var addToList_ServerSide = function(list, season){
var ini_season = season.get(0);
var end_season = season.get(1);
var years_seq = ee.List.sequence(0, list.length().subtract(1))
.map(function (i) {
return ee.List([list.get(i), ini_season, end_season]);
});
return years_seq;
};
print(addToList_ClientSide(['a', 'b', 'c'], ['d', 'e']));
print(addToList_ServerSide(ee.List(['a', 'b', 'c']), ee.List(['d', 'e'])));
// Both of the above print [["a","d","e"],["b","d","e"],["c","d","e"]]
https://code.earthengine.google.com/f0811da96c0eab19b32f0764b321a53a
I don't know if this necessarily does what you want, but it will do the same list manipulation as your addToList_ClientSide
.
Correct answer by Kevin Reid on December 12, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP