1

I have worked on the following code to obtain a fusion of both sensors but when I generate it I get Landsat as an additional property, what can I do?

var s2 = ee.ImageCollection('COPERNICUS/S2')
    .filter(ee.Filter.eq('MGRS_TILE', "19HCD"))
    .filterBounds(subsubcuencas_ms);
//print(s2);

var l8 = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterBounds(subsubcuencas_ms);
//print(l8);

var joined = ee.Join.saveAll('landsat').apply({
  primary: s2,
  secondary: l8,
  condition: ee.Filter.and(
    ee.Filter.maxDifference({
      difference: 1000 * 60 * 60 * 24, // One day in milliseconds
      leftField: 'system:time_start',
      rightField: 'system:time_start',
    }),
    ee.Filter.intersects({
      leftField: '.geo',
      rightField: '.geo',
    })
  )
});

print(joined, 'joined')

1 Answer 1

0

Reading your last comment I understood that the desired output is an image collection of Sentinel-2 images where the Landsat 8 bands are added as bands. After doing the join, the landsat images that matched the indicated condition are saved as a property of each Sentinel-2 image. The only thing you have to do is extract that property, convert it to an image collection and maybe mosaic the images (if you have more than one landsat 8 image that matched the condition). Finally you just need to add this image's bands to the original Sentinel-2 one.

// Map over each of the Sentinel-2 image in joined
var resul = joined.map(function(image){
  // Get property 'landsat' and transform it to an image collection
  // (from a list of images)
  var l8 = ee.ImageCollection.fromImages(image.get('landsat'));
  // Maybe use mosaic if you have more than one match, if not, you can 
  // use first() instead.
  l8 = l8.mosaic();
  // Add the l8 bands to the sentinel-2 ones
  return ee.Image(image).addBands(l8);
});

// Convert the resul to an image collection (from a list of images)
resul = ee.ImageCollection.fromImages(resul);
2
  • yes, I have tried doing this process but it is not what I need as it only joins the collections and does not add sentinel as a band to the landsat image, thanks.
    – María
    Commented Aug 19, 2021 at 3:30
  • I edited the answer based on this last comment that clears out which is the desired output. Commented Aug 19, 2021 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.