1

I'm going to join Landsat-8 and MODIS image collections using the below code but returns nothing. Does anyone know about this?

code link: https://code.earthengine.google.com/2504c97ec795f4f458f7966795110846

enter image description here

Map.centerObject(geometry);

var landsatNDWI = function(img){
  var bands = img.select('SR_B[1-7]').multiply(2.75e-05).add(-0.2);
  var index = bands.normalizedDifference(['SR_B3','SR_B5']).rename('ndwi');
  return index
  .copyProperties(img,['system:time_start','system:time_end']);
};

var modisNDWI = function(img){
  var bands = img.select('sur_refl_b0[1-7]').multiply(0.0001);
  var index = bands.normalizedDifference(['sur_refl_b04','sur_refl_b02']).rename('ndwi');
  return index
  .copyProperties(img,['system:time_start','system:time_end']);
};

var landsat = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
.filterDate('2018','2020')
.filterBounds(geometry)
.map(landsatNDWI);

var modis = ee.ImageCollection("MODIS/006/MOD09GA")
.filterDate('2018','2020')
.filterBounds(geometry)
.map(modisNDWI);




var filter = ee.Filter.equals({
  leftField: 'system:time_start',
  rightField: 'system:time_start'
});

// Create the join.
var simpleJoin = ee.Join.inner();

// Inner join
var innerJoin = ee.ImageCollection(simpleJoin.apply(landsat, modis, filter));

var joined = innerJoin.map(function(feature) {
  return ee.Image.cat(feature.get('primary'), feature.get('secondary'));
});

print('Joined', joined);

1 Answer 1

0

The trouble is that the dates of the Landsat images have a slightly different date format compared to the Modis images. The Landsat collection include the date and time of the images, Modis only the date:

print(landsat.first().date())
>>>   Date (2018-01-13 07:32:29)
print(modis.first().date())
>>>   Date (2018-01-01 00:00:00)

As the system:time_start property is in Unix time, the join will not return anything if there's a slight offset. To fix this, you'll need to strip the hours/minutes/seconds from the Landsat images. Here's a solution using ee.Date().update():

var landsatNDWI = function(img){
  var bands = img.select('SR_B[1-7]').multiply(2.75e-05).add(-0.2);
  var index = bands.normalizedDifference(['SR_B3','SR_B5']).rename('ndwi');
  return index
  .copyProperties(img,['system:time_start','system:time_end']);
};

var modisNDWI = function(img){
  var bands = img.select('sur_refl_b0[1-7]').multiply(0.0001);
  var index = bands.normalizedDifference(['sur_refl_b04','sur_refl_b02']).rename('ndwi');
  return index
  .copyProperties(img,['system:time_start','system:time_end']);
};

var landsat = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
.filterDate('2018','2020')
.filterBounds(geometry)
.map(landsatNDWI)
.map(function(img){return img.set('system:time_start', ee.Date(img.get('system:time_start')).update({hour:0, minute:0, second:0}).millis())})

var modis = ee.ImageCollection("MODIS/006/MOD09GA")
.filterDate('2018','2020')
.filterBounds(geometry)
.map(modisNDWI);

var filter = ee.Filter.equals({
  leftField: 'system:time_start',
  rightField: 'system:time_start'
});

// Create the join.
var simpleJoin = ee.Join.inner();

// Inner join
var innerJoin = ee.ImageCollection(simpleJoin.apply(landsat, modis, filter));

var joined = innerJoin.map(function(feature) {
  return ee.Image.cat(feature.get('primary'), feature.get('secondary'));
});

print('Joined', joined);
>>>  ImageCollection LANDSAT/LC08/C02/T1_L2 (88 elements)

Your Answer

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

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