Skip to main content

given the below posted request, and referring to Normalized Difference Vegetagtion Indeceswhen i try to execute it in request-builder it does not work, and when i try to run it in my code, i receive bad-reuqest.

i am trying to get the ndvi from landsat-8 which identified via the indentifier landsat-ot-l1.


please let me know what is wrong in the below posted request or what i am missing


request:


"input": {
"bounds": {
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
1216491.6636585994,
6596655.883092916
],
[
1210613.043299023,
6580154.492609894
],
[
1233096.18783214,
6590674.129042821
],
[
1216491.6636585994,
6596655.883092916
]
]
]
},
"properties": {
"crs": "http://www.opengis.net/def/crs/EPSG/0/3857"
}
},
"data": [
{
"dataFilter": {
"timeRange": {
"from": "2022-01-01T00:00:00Z",
"to": "2022-01-15T23:59:59Z"
}
},
"type": "landsat-ot-l1"
}
]
},
"output": {
"width": 512,
"height": 375.402,
"responses": [
{
"identifier": "default",
"format": {
"type": "image/tiff"
}
}
]
},
"evalscript": `
//VERSION=3
// Script to extract a time series of NDVI values using
// Sentinel 2 Level 2A data and metadata file.
function setup() {
return {
input: [{
bands: ["B04", "B05"],
units: "DN"
}],
output: {
bands: 1,
sampleType: SampleType.FLOAT32
},
mosaicking: Mosaicking.ORBIT
}

}

// The following function is designed to update the number of
// output bands without knowing beforehand how many there are
function updateOutput(outputs, collection) {
Object.values(outputs).forEach((output) => {
output.bands = collection.scenes.length;
});
}
// function to generate a json file with a list of the NDVI
// dates used in the analysis.
function updateOutputMetadata(scenes, inputMetadata, outputMetadata) {
var dds = [];
for (i=0; i<scenes.length; i++){
dds.push(scenes[i].date)
}
outputMetadata.userData = { "acquisition_dates": JSON.stringify(dds) }
}

function evaluatePixel(samples) {
// Precompute an array to contain NDVI observations
var n_observations = samples.length;
let ndvi = new Array(n_observations).fill(0);

// Fill the array with NDVI values
samples.forEach((sample, index) => {
ndvi[index] = (sample.B05 - sample.B04) / (sample.B05 + sample.B04) ;
});

return ndvi;
}'

This evalscript will work for you:


//VERSION=3
function setup() {
return{
input: [{
bands: ["B04", "B05"]
}],
output: {
id: "default",
bands: 1,
sampleType: SampleType.FLOAT32
}
}
}

function evaluatePixel(sample) {
let ndvi = (sample.B05 - sample.B04) / (sample.B05 + sample.B04)
return [ ndvi ]
}

It is sourced from the documentation site here. Please make full use of the examples contained in here as well as in the Customs Scripts Repository.


thanks


but is there any reason hinders the request posted above in my question from working? also, the evalscript you posted works for me for some satellite missions and does not work for others, such as sentinel-3 any reason for that please?


This question is being answered in another thread


Reply