Google Earth Engine – How to Remap with Number-Limits Instead of Individual Values

google-earth-enginereclassify

I have a rather basic question regarding the reclassification of ImageCollections in GEE. When I want to reclass individual values, I use the remap function as follow

var my_reclass= function(image) {
  var myreclass = image.remap([10 ,12],[  0,   3], null, 'my reclass');    
};

What I would like to do though and I can not find any examples, is to use number limits for my reclassification

e.g.

-1 thru 3 = 5

3.1 thru 8.2 = 1

How can I achieve this?

Best Answer

I think what you need is something like this:

var random = ee.Image.random()

var customRemap = function(image, lowerLimit, upperLimit, newValue) {
  var mask = image.gte(lowerLimit).and(image.lt(upperLimit))
  return image.where(mask, newValue)
}

// values from 0 to 0.5 will be 10, the rest will not change
var remaped = customRemap(random, 0, 0.5, 10) 

Map.addLayer(random)
Map.addLayer(remaped)
Related Question