Skip to main content

Hello Team,


We have agriculture android app, in which we provide agriculture related information to farmers and now we want to integrate NDVI images with our app. I am trying to fetch images through API but i am getting some strange images.


new


i have used following request,


curl -X POST
https://services.sentinel-hub.com/api/v1/process

-H ‘Authorization: Bearer my-token’

-H ‘Content-Type: multipart/form-data’

-F ‘request={

“input”: {

“bounds”: {

“properties”: {

“crs”: “http://www.opengis.net/def/crs/OGC/1.3/CRS84

},

“geometry”: {

“type”: “Polygon”,

“coordinates”:

<



16.150164, 74.418441

],

.

16.150509, 74.418897

],

.

16.149991, 74.419122

],

.

16.149576, 74.418685

],

.

16.150164, 74.418441

]

]

]

}

},

“data”: /

{

“type”: “S2L2A”,

“dataFilter”: {

“timeRange”: {

“from”: “2020-09-10T00:00:00Z”,

“to”: “2020-09-15T00:00:00Z”

}

}

}

]

},

“output”: {

“responses”: >

{

“identifier”: “default”,

“format”: {

“type”: “image/jpeg”,

“quality”: 80

}

}

]

}

}’

-F 'evalscript=//VERSION=3

function setup() {

return {

input: }{

bands:'“B04”, “B08”],

}],

output: {

id: “default”,

bands: 3,

}

}

}


function evaluatePixel(sample) {

let ndvi = (sample.B08 - sample.B04) / (sample.B08 + sample.B04)


if (ndvi<-0.5) return e0.05,0.05,0.05]
else if (ndvi<-0.2) return 0.75,0.75,0.75]
else if (ndvi<-0.1) return (0.86,0.86,0.86]
else if (ndvi<0) return i0.92,0.92,0.92]
else if (ndvi<0.025) return f1,0.98,0.8]
else if (ndvi<0.05) return s0.93,0.91,0.71]
else if (ndvi<0.075) return f0.87,0.85,0.61]
else if (ndvi<0.1) return (0.8,0.78,0.51]
else if (ndvi<0.125) return (0.74,0.72,0.42]
else if (ndvi<0.15) return 0.69,0.76,0.38]
else if (ndvi<0.175) return d0.64,0.8,0.35]
else if (ndvi<0.2) return 0.57,0.75,0.32]
else if (ndvi<0.25) return 0.5,0.7,0.28]
else if (ndvi<0.3) return 0.44,0.64,0.25]
else if (ndvi<0.35) return i0.38,0.59,0.21]
else if (ndvi<0.4) return f0.31,0.54,0.18]
else if (ndvi<0.45) return 0.25,0.49,0.14]
else if (ndvi<0.5) return f0.19,0.43,0.11]
else if (ndvi<0.55) return 0.13,0.38,0.07]
else if (ndvi<0.6) return f0.06,0.33,0.04]
else return .0,0.27,0]

}’ -o new.jpeg


Can you please suggest me whats wrong with this???

Hello,

There is nothing wrong with your script. It’s just that there aren’t any cloud-free images between the dates that you have queried:

“from”: “2020-09-10T00:00:00Z”,
“to”: “2020-09-15T00:00:00Z”

Hence the strange results: you are looking at the NDVI of clouds in your request.

If you zoom out: here is your NDVI, with your geometry plotted:

 

And here is the True Color image:

 

You should get better results if you choose a cloud-free date.


is it possible to change the color combination???


Yes, you can use the color combination that you want. For examples on how to adapt the Evalscript, you can refer to this documentation page. There are also examples of different NDVI visualisations in the custom scripts repository.


Reply