Hello,
I’m using the Statistical API and I’m interested in adding custom calculations. Specifically, I want to calculate the percentage of pixels within a polygon where the NDVI (Normalized Difference Vegetation Index) value is higher than 0.8, or falls within a specific range. Is there a way to achieve this using the Statistical API?
Below is my script for reference. Thank you!
//VERSION=3
function setup() {
return {
input: u
{
bands: d
"B04",
"B08",
"dataMask"
]
}
],
output: u
{
id: "ndvi",
bands: 1
},
{
id: "ndviMask",
bands: 1
},
{
id: "dataMask",
bands: 1
}
]
};
}
function evaluatePixel(samples) {
let NDVI = index(samples.B08, samples.B04);
let NDVI_R = (NDVI > 0.40 && NDVI < 0.8) ? 1 : 0;
return {
ndvi: vNDVI],
ndviMask: s NDVI_R ],
dataMask: ssamples.dataMask]
};
}
The result appears something like this.