I am trying to merge 3 satellite images of 3 times. The images are median images. I have used the following code but there is an error.

var maskL8 = function(image_m) {
  var qa = image_m.select('BQA');
  var mask = qa.bitwiseAnd(1 << 4).eq(0);
  return image_m.updateMask(mask);

var collection_1 = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterDate('2018-06-16', '2018-10-15')
Map.addLayer(collection_1, {bands: ['B5', 'B4', 'B3'], max: 0.3}, 'collection_1');

var maskL8 = function(image_s) {
  var qa = image_s.select('BQA');
  var mask = qa.bitwiseAnd(1 << 4).eq(0);
  return image_s.updateMask(mask);

var collection_2 = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterDate('2018-03-16', '2018-05-15')
Map.addLayer(collection_2, {bands: ['B5', 'B4', 'B3'], max: 0.3}, 'collection_2');

var maskL8 = function(image_w) {
  var qa = image_w.select('BQA');
  var mask = qa.bitwiseAnd(1 << 4).eq(0);
  return image_w.updateMask(mask);

var collection_3 = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterDate('2017-11-16', '2018-02-15')
Map.addLayer(collection_3, {bands: ['B5', 'B4', 'B3'], max: 0.3}, 'collection_3');

var collectionFromConstructor = ee.ImageCollection([collection_1, collection_2, collection_3]);
print('collectionFromConstructor: ', collectionFromConstructor);

var collectionFromImages = ee.ImageCollection.fromImages(
  [ee.Image(3), ee.Image(4), ee.Image(5)]);
print('collectionFromImages: ', collectionFromImages);

var mergedCollection = collectionFromConstructor.merge(collectionFromImages);
print('mergedCollection: ', mergedCollection);
Map.addLayer(mergedCollection, {bands: ['B5', 'B4', 'B3'], max: 0.3}, 'mergedCollection');

Error says:

mergedCollection: Tile error: Expected a homogeneous image collection, but an image with incompatible bands was encountered:
  First image type: 12 bands ([B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, BQA]).
Current image type: 1 bands ([constant]).
          Image ID: 0
Some bands might require explicit casts.

Error in using collection_1.merge(collection_2):

"collection_1.merge is not a function."
  • Hey. Please format your code properly using the { } button so it is more readable. Also, mention what software are you using (I guess it is GEE) and add the proper tag for more visibility. – Marcelo Villa Jul 31 at 17:31
  • Yes, I am using GEE. I am sorry, I couldn't format the code. Can you please tell me why this error is showing? What is the way to use .merge function? – Shihab Nur Jul 31 at 18:11
  • Looks like you tagged the question with "google-earth", when it's really a "google-earth-engine" question. They are significantly different products, and you'll be more likely to get an answer if you tag it with the right one. – Christiaan Adams Aug 1 at 0:49

Your Answer

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

Browse other questions tagged or ask your own question.