0

Given that an area of interest is partially cloud covered, how can you mosaic two separate collections to get a single cloud free mosaic?

Given I have a S2 image over a study area, that has a cloudy eastern half:

var collection = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2017-01-01', '2017-03-01')
.filterBounds(geometry5)

and imagery over the same region from a previous date that has a cloudy western half:

var collection2 = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2016-11-13', '2016-12-23')
.filterBounds(geometry4) 

Is there a way to mosaic the data together to get a single collection/dataset?

This is a straightforward task with gdal but I can't find it in the Earth Engine documentation.

As a visual example:

I have this collection:

cloud free western collection

and this separate collection:

cloud free eastern collection

and I want to merge/mosaic them into a single collection:

Final complete mosaic

  • What is the mosaicing strategy you want? Min/Max pixel value? image 2 on top of image 1? Mean value in overlapping areas? – Kersten Mar 16 '18 at 9:43
  • Ideally image 1 on top of image 2 – Nathan Thomas Mar 16 '18 at 13:14
2

Both dates you provide the collections contain multiple images over the sundarban region. A ImageCollection is a spatial as well as temporal collection of images. To display them you have to reduce them to an image first.

In your case it looks like you tried to display the collection, in which case GEE will take the first non-zero value for each pixel stack in your collection. You can recreate that by using the .firstNonNull() reducer.

var date1 = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2017-01-01', '2017-03-01')
.filterBounds(sundarban1)
.reduce(ee.Reducer.firstNonNull())
.clip(sundarban1)

var date2 = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2016-11-13', '2016-12-23')
.filterBounds(sundarban2)
.reduce(ee.Reducer.firstNonNull())
.clip(sundarban2)

The result are two images, each containing data for the different polygons you've drawn (in my case sundarban1 and sundarban2).

To merge both into a single image with a similar logic as GDAL you can use the .mosaic operator. The last image in the list will be on top.

var mosaic = ee.ImageCollection.fromImages([date2, date1]).mosaic()

The complete script on GEE: https://code.earthengine.google.com/e61e918ddbfac828ccf313f186a64e24

  • Awesome. In a step I didn't include I did indeed reduce them to get images. I did play around with the '.mosaic()' call but wasn't sure of the syntax! – Nathan Thomas Mar 16 '18 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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