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}),
image)
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
Best Answer
You function is fine, you just need to move one parenthesis, from
ee.Number(image.get('class').eq(8))
toee.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 aFeatureCollection
each element is aFeature
, so I'd usefeat
, but of course it works with any name you use, and that is up to you.