I’m doing pretty good in R but can’t figure out how to translate this javascript (at least I think it’s javascript…might be python?) into R:
/*
Author of the script: Carlos Bentes
*/
// Normalized Difference Vegetation Index
var ndvi = (B08-B04)/(B08+B04);
// Threshold for vegetation
var veg_th = 0.4;
// Simple RGB
var R = 2.5*B04;
var G = 2.5*B03;
var B = 2.5*B02;
// Transform to Black and White
var Y = 0.2*R + 0.7*G + 0.1*B;
var pixel = [Y, Y, Y];
// Change vegetation color
if(ndvi >= veg_th)
pixel = [0.1*Y, 1.8*Y, 0.1*Y];
return pixel;
This is the Green City Index which is part of the repository of custom scripts that can be used with Sentinel-Hub services.
Specifically I’m having issues with
var pixel = [Y, Y, Y];
And
if(ndvi >= veg_th)
pixel = [0.1*Y, 1.8*Y, 0.1*Y];
return pixel;
I think var pixel = [Y, Y, Y];
is the same as pixel <- c(Y, Y, Y)
? Which means in the if
statement I’d have
if(ndvi >= veg_th){
pixel <- c(0.1*Y, 1.8*Y, 0.1*Y)
return(pixel)
}
But I’m not getting results: Error in if (ndvi >= veg_th) { : argument is not interpretable as logical
Thanks for taking a look!