supercontra
supercontra

Reputation: 175

Scale values of raster in Google Earth Engine

I have several layers I want to combine using map algebra in Google Earth Engine. However, I need to scale them to have 1-5 values so they are comparable. Here is an example of one layer, slope, which I need to scale to values in the range 1-5.

// Load the SRTM image.
var srtm = ee.Image('CGIAR/SRTM90_V4');

// Apply an algorithm to an image.
var slope = ee.Terrain.slope(srtm);

var Vis = {
  min: 1.0,
  max: 30.0,
  palette: ['001137', '0aab1e', 'e7eb05', 'ff4a2d', 'e90000'],
};
Map.setCenter(-74.93, 4.71, 5);


// Display the result.
 // Center on the Grand Canyon.
Map.addLayer(slope, Vis, 'slope');

Upvotes: 0

Views: 1773

Answers (1)

Val
Val

Reputation: 7023

I would use unitScale to first get the slope in the range 0 - 1, then multiply by 4, which gets it to 0 - 4 ... if you want 1-5, just add 1 in the end:

var slope2 = slope.unitScale(0,90).multiply(4).add(1)

In this case I use 0 and 90 to scale the image, which is the full theoretical range ... depending on your AOI, you may want to use a smaller range.

Upvotes: 1

Related Questions