Skip to main content

Code examples

Formation of requests according to rate limits with Python, JavaScript/Node.js

How to render AOI with NDVI on Google Maps

How to render the whole scene on Mapbox

Formation of requests according to rate limits

Python example

import time
import requests
url = "https://api-connect.eos.com/api/gdw/api?api_key=<your_api_key>"
RATE_LIMIT = 10 # ten requests per minute
MINUTE_IN_SECONDS = 60
payload = {
"type": "mt_stats",
"params":
{
"bm_type": "NDVI",
"date_start": "2020-01-01",
"date_end": "2020-09-20",
"geometry":
{
"coordinates":
[[
[lon,lat],
[lon,lat],
.........,
[lon,lat]
]],
"type": "Polygon"
},
"reference": "ref_20200924-00-00",
"sensors": ["sentinel2"],
"limit": 10
}
}
headers = {
'Content-Type': 'application/json'
}
for request in range(10):
response = requests.request("POST", url, headers=headers, json=payload)
time.sleep(MINUTE_IN_SECONDS / RATE_LIMIT)
print(response.status_code, response.json())

Bash example

while :
do
curl --location --request POST 'https://api-connect.eos.com/api/gdw/api?api_key=<your_api_key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"type": "bandmath",
"params": {
"view_id": "view_id",
"bm_type": "bm_type",
"geometry": {
"type": "Polygon",
"coordinates": [[
[lon,lat],
[lon,lat],
.........,
[lon,lat]
]]
},
"name_alias":"alias name",
"reference": "ref_datetime"
}
}'
sleep 5s
done

JavaScript/Node.js example

const https = require('https')

const data = JSON.stringify({
type: 'mt_stats',
params:
{
bm_type: 'NDVI',
date_start: '2020-01-01',
date_end: '2020-09-20',
geometry:
{
coordinates:
[
[
[-86.86718, 41.317464],
[-86.86718, 41.331596],
[-86.862631, 41.331596],
[-86.862631, 41.317464],
[-86.86718, 41.317464]
]
],
type: 'Polygon'
},
reference: 'ref_20200924-00-00',
sensors: ['sentinel2'],
limit: 10
}
})

const options = {
hostname: 'api-connect.eos.com',
port: 443,
path: '/api/gdw/api?api_key=<your_api_key>',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}

const RATE_LIMIT = 10 # ten requests per minute
const MINUTE_IN_SECONDS = 60

setInterval(function() {
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', d => {
process.stdout.write(d)
})
})
req.on('error', error => {
console.error(error)
})
req.write(data)
req.end()
}, MINUTE_IN_SECONDS / RATE_LIMIT * 1000); // request each 6 sec (6000 milliseconds)