遍历GEE FeatureCollection

时间:2019-04-02 22:57:17

标签: google-earth-engine

对imageCollection进行迭代的过程已被详细记录,但featureCollection并非如此。尝试应用它时,会出现一些错误。我在这里展示其中之一。 如果有人成功完成了此过程,将不胜感激。

var dict1 = ee.Dictionary({'Name': null, 'cultivo': null, 'imageId':null,'sum':null})

var n_list = ee.List(ee.Feature(null,dict1));
print(n_list)

var sum2 = function(feature,list){
  var actual = feature.get('sum')
  var previous = ee.Feature(ee.List(list).get(-1))
  var added = actual.add(previous)
  return ee.List(list).add(added)
    };

var summarize = ee.FeatureCollection(ee.List(sumChange.iterate(sum2,n_list)));
print('summarise',summarize)

错误 actual.add is not a function

1 个答案:

答案 0 :(得分:0)

正确的方法如下,

var dict1 = ee.Dictionary({'Name': null, 'cultivo': null, 'imageId':null,'sum':0})
//
var n_list = ee.List([ee.Feature(sumChange.first().geometry(),dict1)]);
//print(n_list)

var sum2 = function(feature,list){
  var actual = ee.Number(feature.get('sum'))
  var previous = ee.Number(ee.Feature(ee.List(list).get(-1)).get('sum'))
  var keepProperties = ['Name', 'cultivo', 'imageId','sum'];
  var added = actual.add(previous)
  return ee.List(list).add(feature.set('sumatoria', added).copyProperties(feature,keepProperties))
    };

var summarize = ee.FeatureCollection(ee.List(sumChange.iterate(sum2,n_list)));
print('summarise',summarize)