Skip to main content

Hello all,


I am a very newbie using the Sentinelhub API. I currently have requested imagery of Pleiades, and I am trying to download it through the Sentinel Hub Python package by using the following code:


So my question is, how can I download it to my disk in a tiff format?


(I have already imported the libraries and set my credentials),*


response = oauth.post('https://services.sentinel-hub.com/api/v1/process',*
headers={"Authorization" : "Bearer {}".format(token)},
json={
'input': {
"bounds": {
"properties": {
"crs": "http://www.opengis.net/def/crs/EPSG/0/{}".format(4326)
},
"bbox": [-46.74869460121712, -0.9729251789917431, -46.64665760474313, -0.889532997887468]
},
"data": [{
"type": "CUSTOM",
"dataFilter": {
"collectionId": collectionid,
"timeRange": {
"from": "2017-06-16T00:00:00Z",
"to": "2017-12-17T00:00:00Z"
}
}
}]
},
"output": {
'resx': 0.0000938,
'resy': 0.0000938,
"responses": [
{
"identifier": "default",
"format": {
"type": "image/tiff"
}
}
]
},
"evalscript": """
//VERSION=3
function setup() {
return {
input: [{"bands": ["B0", "B1", "B2", "B3"], units: "DN"}],
output: { id: "default", bands: 4, sampleType: SampleType.UINT16}
};
}
function evaluatePixel(sample) {
return [sample.B0, sample.B1, sample.B2];
}
"""
})

#Saving the response content in tif file

with open(‘test_out.tif’, ‘wb’) as f:

f.write(response.content)

Hi,

I assumed you wanted to download all 5 Pleaides bands in your output file and I adjusted your evalscript accordingly. Some other examples of evalscripts you can use for Pleiades data can be found here.

In the snippet below, you only need to input your collectionId (get it in your SH Dashboard) in the beginning and it should download the tif file for you:

import requests

collectionId = "" # input your collectionId

url = "https://services.sentinel-hub.com/api/v1/process"

headers = {
"Content-type": "application/json",
'Authorization': f'Bearer {token["access_token"]}'
}

json={
'input': {
"bounds": {
"properties": {
"crs": "http://www.opengis.net/def/crs/EPSG/0/{}".format(4326)
},
"bbox": [-46.74869460121712, -0.9729251789917431, -46.64665760474313, -0.889532997887468]
},
"data": [{
"type": f"byoc-{collectionId}",
"dataFilter": {
"timeRange": {
"from": "2017-06-16T00:00:00Z",
"to": "2017-12-17T00:00:00Z"
}
}
}]
},
"output": {
'resx': 0.0000938,
'resy': 0.0000938,
"responses": [
{
"identifier": "default",
"format": {
"type": "image/tiff"
}
}
]
},
"evalscript": """
//VERSION=3
function setup() {
return {
input: [{"bands": ["B0", "B1", "B2", "B3", "PAN"], units: "DN"}],
output: { id: "default", bands: 5, sampleType: SampleType.UINT16}
};
}
function evaluatePixel(sample) {
return [sample.B0, sample.B1, sample.B2, sample.B3, sample.PAN];
}
"""
}

response = oauth.post(url, headers=headers, json=json)

with open('test_out.tif', 'wb') as f:
f.write(response.content)

Best


Hello, thank you so much for your solution. Now I am having another issue, I can’t get the image that I am requesting in a 2-meter resolution; It seems to be because of the image size. Thus I am trying to split the bounding box into pieces by using the next code:

from sentinelhub import BBoxSplitter, CRS
bbox_splitter = BBoxSplitter(r-5204040.878257746808231,-108310.740786702488549,-5192682.17176818754524,-99026.338571377724293], CRS(3857), (2, 2))

But I get the next error: The list of shapes must contain shapes of types <class ‘type’>, <class ‘type’> or subtype of <class ‘abc.ABCMeta’>


Hi,

you will need to create shapely polygon based on your coordinates first. You can use sentinelhub’s BBox object. Try:

from sentinelhub import BBoxSplitter, CRS, BBox
my_bbox = BBox(x-5204040.878257746808231,-108310.740786702488549,-5192682.17176818754524,-99026.338571377724293], CRS(3857))
bbox_splitter = BBoxSplitter(rmy_bbox.geometry], CRS(3857), (2, 2))

Best


Reply