I try to add a new Feature to the large Feature Collection, but with a function set() its override the whole list to each feature. But my purpose is to add each Value from an Array to the corresponding feature in the FeatureCollection. Can anybody help me?

    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);
     //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);

So, if you can see, my code add the whole Array [limit] to each property in the FeatureCollection, not a first Value from the Array to the first property and so on... Could anybody help me? thank you


If you have a smallish number of features, you can convert the feature collection to a list, convert the array to a list, zip() them together, map a function over the lists to set the property. Toy example:

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));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.