forked from sentinel-hub/custom-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (32 loc) · 1.17 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//VERSION=3
//This script visualizes the occurrence change intensity layer according to the Global Surface Water data user guide.
//Set up input and output settings
function setup() {
return {
input: ["change"],
output: {
bands: 3,
sampleType: "AUTO"
}
}
}
//Create color ramp
const ramps = [
[0, 0xff0000], //-100% loss of occurrence (Pure red)
[100, 0x000000], //No change (Black)
[200, 0x00ff00] //100% increase in occurrence (Pure lime green)
];
//Create visualizer
const visualizer = new ColorRampVisualizer(ramps);
//EvaluatePixel function
function evaluatePixel(sample) {
if (sample.change == 253){ //Not water
return [1, 1, 1] //Return White
}else if (sample.change == 254){ //Unable to calculate a value due to no homologous months
return [0.533, 0.533, 0.533] //Return Dark gray
}else if (sample.change == 255){ //No data
return [0.8, 0.8, 0.8] //Return Light gray
}else if (sample.change <= 200){ //loss and increase of occurrence
return [visualizer.process(sample.change)[0], visualizer.process(sample.change)[1], visualizer.process(sample.change)[2]]; //Return color ramp values
}
}