Skip to main content

Hi, is it possible to have multiple layers when calling the WMS api to retrieve NDVI images?

In my scenario i am retrieving an NDVI image using this script

Sentinel-Hub custom scripts

Normalized difference vegetation index



A repository of custom scripts that can be used with Sentinel-Hub services.






My query has a defined polygon, so only the polygon is “mapped” according to the script parameters, while the remaining part of the bbox is uniformly colored in dark green.


I would like to have the remaining part of my image has if i was using the true color layer.


Thanks in advance for your help

Hi,

unfortunately , that is not supported in one wms request.
wms api will only return data (in your case NDVI) for the defined polygon, and therefore not possible to also return true color data outside your defined polygon.

However, it is possible to make the remaining part of the NDVI image outside the defined polygon, transparent rather than dark green. and then overlay the NDVI image over a true color image that you retrieved in a separate wms request.

perhaps this may help you, below is an example of how you can add transparecy to ndvi image as a fourth channel in your script. See also documentation

function evaluatePixel(samples) {
let val = index(samples.B08, samples.B04);
if (samples.dataMask == 1){
return colorBlend(val,
[-0.2, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 ],
[[0, 0, 0,1], // < -.2 = #000000 (black)
[165/255,0,38/255,1], // -> 0 = #a50026
[215/255,48/255,39/255,1], // -> .1 = #d73027
[244/255,19739/255,67/255,1], // -> .2 = #f46d43
[253/255,174/255,97/255,1], // -> .3 = #fdae61
[254/255,224/255,139/255,1], // -> .4 = #fee08b
[255/255,255/255,191/255,1], // -> .5 = #ffffbf
[217/255,239/255,139/255,1], // -> .6 = #d9ef8b
[166/255,217/255,19736/255,1], // -> .7 = #a6d96a
[102/255,189/255,99/255,1], // -> .8 = #66bd63
[26/255,152/255,80/255,1], // -> .9 = #1a9850
[0,19734/255,55/255,1] // -> 1.0 = #006837
]);}
else{
return [0,0,0,0]
}
}

Best


Hi,
thanks for your response, however with this code the layer doesn’t work anymore, and i cannot figure out why. Can you tell me if i have to setup something before it works?


Hi,

maybe you are missing something in the wms request url

the request below should work

https://services.sentinel-hub.com/ogc/wms/instance_id?REQUEST=GetMap&CRS=CRS:84&BBOX=12.643111,41.837339,12.765986,41.921183&GEOMETRY=POLYGON ((12.643111 41.901766,12.674688 41.920162,12.735096 41.921183,12.763927 41.895122,12.765986 41.861891,12.727545 41.837339,12.663018 41.841432,12.643111 41.901766))&LAYERS=VEGETATION_INDEX&WIDTH=512&HEIGHT=468&FORMAT=image/png&TIME=2021-04-07/2021-05-07

if it still wont work, please share the error messages you get

best regards


I was missing the setup function, thanks a lot.


Sorry for the late update


Reply