0

I want to make a function (possibly using Currying method) in GEE to do a modification of my featureCollection. In the code bellow I wrote a function_infunction to add a new property "label" (which is an integer value given as an input argument) to the feature collection:

var addLabel = function(l){
return function(feature) {
return feature.set({label:l});
};
};

var DFV_coll = cc_features.filter(ee.Filter.eq('CUL','A')).map(addLabel(11));

It works well. I do however want to extend this function so that I can relate the value of the property "lable" to another proberty "CUL". This means that if the property "CUL" has 5 different valus inside my featureCollection, I want the correspoding "label" values to be set accordingly. I am thinking of providing a dictionary of key/values like:

var dict = {'A':11, 'B':2, 'C':-1 ...}

And do this all at once inside my function. How should I approach this extention?

1 Answer 1

1

You can use this approach:

var fc = ee.FeatureCollection([
  ee.Feature(null, { 'CUL': 'A' }),
  ee.Feature(null, { 'CUL': 'B' }),
  ee.Feature(null, { 'CUL': 'C' }),
]);

var culLabels = ee.Dictionary({
  'A': 11,
  'B': 2,
  'C': -1
});

function addLabelProperty(feature) {
  var cul = feature.get('CUL');
  var labelValue = culLabels.get(cul);
  return feature.set('label', labelValue);
}

fc = fc.map(addLabelProperty);
1
  • Excellent use of dictionary. Thanks @Iago Mendes! Commented Mar 7, 2024 at 8:19

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.