Google地球引擎:将功能设置为FeatureCollection,但不是整个数组

时间:2017-09-08 09:23:03

标签: arrays properties set google-earth-engine

我尝试向大型特征集添加新特征,但是使用函数set()它会覆盖每个特征的整个列表。但我的目的是将Array中的每个值添加到FeatureCollection中的相应功能。有人能帮助我吗?

    var table = ee.FeatureCollection(ft:.....blablabla);

    **//Create an Array from the property DN in the FeatureCollection:**
        var propert = table.limit(100).aggregate_array('DN');
    *// Values less than 1 will be set to 1, larger than 1== 0:* 
        var limit =  ee.Array(propert).lt(1);
        print(limit);
     //Function, that add the list! of features (limit) to new property (Class) in the FeatureCollection ("table"). 
        var addFeature = function(ar) {
          return ar.set({Class: limit});
     //Map throw the Featurecollection table
        var areaAdded = table.limit(100).map(addArea);
        };

所以,如果你能看到,我的代码将整个Array [limit]添加到FeatureCollection中的每个属性,而不是从Array到第一个属性的第一个值,依此类推...... 有人能帮助我吗?谢谢

1 个答案:

答案 0 :(得分:0)

如果您的功能数量很少,您可以将要素集转换为列表,将数组转换为列表,zip()将它们组合在一起,在列表上映射函数以设置属性。玩具示例:

var features = [
  ee.Feature(ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), {name: 'Voronoi'}),
  ee.Feature(ee.Geometry.Point(-73.96, 40.781), {name: 'Thiessen'}),
  ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {name: 'Dirichlet'})
];

var fromList = ee.FeatureCollection(features);

var array = ee.Array([2, 3, 5]);

var lists = fromList.toList(fromList.size()).zip(array.toList());

var features = ee.FeatureCollection(lists.map(function(l) {
  return ee.Feature(ee.List(l).get(0)).set('foo', ee.List(l).get(1));
}));
print(features);