Hi @reutkeller ,
I have a couple of remarks and suggestions, so let’s go through them one-by-one.
function setup
The mosaicking parameter in function setup()
must be set to TILE to access the tileOriginalId
:
function setup() {
return {
input: [{
datasource: "LANDS89",
bands: ["B02","B03","B04","B05","B06","B07" ]
},
{
datasource: "S2L2A",
bands: ["B02","B03","B04","B8A","B11","B12"]
}
],
output: [{
bands: 12,
sampleType:"FLOAT32"
}],
mosaicking: Mosaicking.TILE
}
}
updateOutputMetadata
I see in your function evaluatePixel()
that you only return data for the first position of the returned data array:
function evaluatePixel(samples) {
var l8 = samples.LANDS89[0]
var s2 = samples.S2L2A[0]
...
Note: With Mosaicking.TILE
this will only return data from the first tile in the data array and there won’t be any mosaicking performed.
So if you only need the tile ID for exactly this one acquisition, your function updateOutputMetadata
should look like this:
function updateOutputMetadata(scenes, inputMetadata, outputMetadata) {
outputMetadata.userData = { "original_tile_id": scenes.S2L2A.scenes[0].tileOriginalId }
}
scenes.S2L2A.scenes[0].tileOriginalId
is needed because you first access the scenes object containing scenes for Sentinel-2 and Landsat, then access the datacollection Id (you specified the id as S2L2A), within the data collection you access the first tile of the data array with scenes[0] and then draw out the tileOriginalId.
You can also preselect the S2 scenes and write them to a variable if you prefer that:
function updateOutputMetadata(scenes, inputMetadata, outputMetadata) {
var scenes_s2 = scenes.S2L2A;
outputMetadata.userData = { "original_tile_id": scenes_s2.scenes[0].tileOriginalId }
}
responses
Note that function updateOutputMetadata
generates a JSON output file that also needs to be added to the request responses like this:
responses=[
SentinelHubRequest.output_response('default', MimeType.TIFF),
SentinelHubRequest.output_response('userdata', MimeType.JSON),
],
The response will be a .tar
file that contains the default.TIFF
and userdata.JSON
files.
return list of all tile ids
If you want the whole list of tiles in the specified location and time range, you could push all tileOriginalId
to a list and return this in the JSON like this:
function updateOutputMetadata(scenes, inputMetadata, outputMetadata) {
var scenes_s2 = scenes.S2L2A;
var dds = [];
for (i=0; i<scenes_s2.scenes.length; i++){
dds.push(scenes_s2.scenes[i].tileOriginalId)
}
outputMetadata.userData = { "original_tile_ids": JSON.stringify(dds) }
}