0

I want to add the values of two properties A and B (both of type string) into a new property A_B to every feature inside the featureCollection.

I tried ee.Feature.get() and ee.Feature.getString() to read the values of properties into two new variables inside my map() function. But they return not "string" values but "tree" type structures.

var add_mix_AB = function(f){
  var A = f.getString(['A']);
  var B = f.getString(['B']);
  return f.set('A_B', A+B);
 };
2
  • This is a good example of the difference between programming on the client and server side. Since this function will be evaluated on the server side, cat (server-side) must be used instead of + (client-side) to avoid an error. Commented Feb 15 at 16:02
  • Thanks @Jonathan V. Solórzano for additional clarification. Commented Feb 19 at 9:53

1 Answer 1

0

OK I figured out the issue was :

  1. In the way I "got" the strings. (the name of property should not have been given inside a list.)

  2. "added" them together. (I had to use the .cat() function to add two strings)

The corrected snipet will be :

var add_mix_AB = function(f){
  var A = f.getString('A');
  var B = f.getString('B');
  return f.set('A_B', A.cat(B));
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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