I am working on land-use classification and I would like to merge some classes from my training dataset. I've a FeatureCollection with over a hundred polygons (features), with all of them having a property 'class' to them with a number from 1 to 17 representing the different classes. I would like to replace from all Features the property which have a class 8 to be replaced by class 9.

I've been trying different things, and I think it should look something like this:

var conditional = function(image){
  return ee.Algorithms.If(ee.Number(image.get('class').eq(8)),
  image.set({class: 9}),

var test = table.map(conditional)

In which:

  • table contains my FeatureCollection with polygons
  • class is the property on which the conditional function must be based
  • 8 and 9 are linked to the 'class' properties

1 Answer 1


You function is fine, you just need to move one parenthesis, from ee.Number(image.get('class').eq(8)) to ee.Number(image.get('class')).eq(8). Also, in the code you posted you are missing the closing bracket.

As a suggestion, I wouldn't use image for that function argument, it's confusing because when you loop (map) over a FeatureCollection each element is a Feature, so I'd use feat, but of course it works with any name you use, and that is up to you.

var conditional = function(feat) {
  return ee.Algorithms.If(ee.Number(feat.get('class')).eq(8),
  feat.set({class: 9}),
var test = table.map(conditional)
  • To group multiple classes it is possible to repeat this process. Can I however also add an .or statement to add class 7 to be transformed into 9 too?
    – S Verhoef
    May 16, 2019 at 12:15
  • yes, in ee.Algorithms.If you can use any condition you want May 16, 2019 at 12:40

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.