I use curl to run on the platform and obtain ndvi images from the sentinel, which works correctly. But when I created an evalscript to apply Jenks’ natural breaks and obtain the result, I couldn’t do it. Someone will have an evalscript to obtain this result.
I use the following example for the ndvi Examples for S2L2A -polygon
Hi Luis,
Could you share the Evalscript that you are trying to implement and the error message you are getting so we can debug this together please?
Are you trying to implement the natural breaks across a time-series of values or spatially? I am asking because Sentinel Hub operates on a per-pixel basis (in case you weren’t aware).
First of all, thank you for answering me. Yes I know that the sentinel works per pixel. The script I currently have to get the NDVI is this
The issue is that I don’t know how to apply a Jenks formula to the NDVI result to obtain the natural breaks. In other words, I don’t have that formula and I don’t know how to apply it to the NDVI either.
curl_setopt_array($curl, [
CURLOPT_URL => “https://services.sentinel-hub.com/api/v1/process”,
CURLOPT_RETURNTRANSFER => true,
//CURLOPT_BINARYTRANSFER => true,
CURLOPT_CUSTOMREQUEST => “POST”,
CURLOPT_POSTFIELDS =>‘{“input”: {
“bounds”: {
“properties”: {
“crs”: “http://www.opengis.net/def/crs/EPSG/0/4326”
},
“geometry”: {
“type”: “Polygon”,
“coordinates”: [’.((is_array($datos->coordenadas))?(json_encode($datos->coordenadas)):(‘’)).‘]
}
},
“data”: [{“id”: “s1”,
“type”: “sentinel-1-grd”,
“dataFilter”: {
“timeRange”: {
“from”: "’.$datos->from.‘T00:00:00Z",
“to”: "’.$datos->to.‘T00:00:00Z"
}
},
“processing”: {
“orthorectify”: “true”,
“backCoeff”: “SIGMA0_ELLIPSOID”
}
},
{“id”: “l2a”,
“type”: “sentinel-2-l2a”,
“dataFilter”: {
“timeRange”: {
“from”: "’.$datos->from.‘T00:00:00Z",
“to”: "’.$datos->to.‘T00:00:00Z"
}
}
}]
},
“output”: {
“width”: 1024,
“height”: 1024,
“responses”: [{
“identifier”: “default”,
“format”: {“type”: “image/png”}
}]
},
“evalscript”: “//VERSION=3\nfunction setup() {\nreturn {\ninput: [{\ndatasource: "s1",\nbands: ["VV", "VH"]\n}, {\ndatasource: "l2a",\nbands: ["B08", "B04", "SCL"]\n}\n],\noutput: [{\nbands: 3\n}]\n}}\nfunction toDb(linear) {\n// Convert the linear backscatter to DB (Filgueiras et al. (2019), eq. 3)\nreturn 10 * Math.LN10 * linear\n}\nfunction calc_s1_ndvi(sigmaVV, sigmaVH) {\n// Convert sigma0 to Decibels\nlet vh_Db = toDb(sigmaVH)\nlet vv_Db = toDb(sigmaVV)\n// Calculate NRPB (Filgueiras et al. (2019), eq. 4)\nlet NRPB = (vh_Db - vv_Db) / (vh_Db + vv_Db)\n// Calculate NDVI_nc with approach A3 (Filgueiras et al. (2019), eq. 14)\nlet NDVInc = 2.572 - 0.05047 * vh_Db + 0.176 * vv_Db + 3.422 * NRPB\nreturn NDVInc\n}\n// Create an NDVI visualiser\nvar viz = new ColorMapVisualizer([\n[0.0, 0x000000],\n[0.1, 0xd73027],\n[0.2, 0xf46d43],\n[0.3, 0xfdae61],\n[0.4, 0xfee08b],\n[0.5, 0xffffbf],\n[0.6, 0xd9ef8b],\n[0.7, 0xa6d96a],\n[0.8, 0x66bd63],\n[0.9, 0x1a9850],\n[1.0, 0x006837]\n])\nfunction evaluatePixel(samples) {\nvar s1 = samples.s1[0]\nvar s2 = samples.l2a[0]\n// Use the S2-L2A classification to identify clouds\nif ([7, 8, 9, 10].includes(s2.SCL)) {\n// If clouds are present use S1 NDVI\nlet s1_ndvi = calc_s1_ndvi(s1.VV, s1.VH) // Calculate S1 NDVI\nreturn viz.process(s1_ndvi)\n} else {\n// Otherwise use s2 NDVI\nlet ndvi = index(s2.B08, s2.B04) // Calculate S2 NDVI\nreturn viz.process(ndvi)\n}\n}”
}’,
CURLOPT_HTTPHEADER => [
“Accept-Encoding: image/png”,
“content-type: application/json”,
//“Accept-Encoding: application/tar”,
//“Content-Type: multipart/form-data”,
"Authorization: Bearer ".$this->keySentinel
]
]);
If you have one to save me all the research and development. I would appreciate it