I just got acquainted with the ‘Joins’ command. I wrote the following code to practice. But instead of 18 elements, it displays 324 elements. How to make this code with the same join structure to give me 18 two-band elements from two sentinel Image Collections and why does this code show 324 elements?
code link: https://code.earthengine.google.com/f0aacb653bfaff59a5f31cd963557750
code :
Map.centerObject(geometry);
// Function - Calculate S2_1 NDVI
var ndvi1 = function(img){
var bands = img.select(['B2','B3','B4','B8']).multiply(0.0001)
.clip(geometry);
var index = bands.normalizedDifference(['B8','B4']).rename('NDVI_S2');
return index
.copyProperties(img,['system:time_start','system:time_end','system:index']);
};
// Get S2_1 NDVI images
var S2_1 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterBounds(geometry)
.filterDate('2018-10-24','2019-06-30')
.filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE',20))
.map(ndvi1);
print('S2 NDVI ImageCollection',S2_1);
// Function - Calculate S2_2 NDVI
var ndvi2 = function(img){
var bands = img.select(['B2','B3','B4','B8']).multiply(0.0001)
.clip(geometry);
var index = bands.normalizedDifference(['B8','B4']).rename('NDVI_S2');
return index
.copyProperties(img,['system:time_start','system:time_end','system:index']);
};
// Get S2_2 NDVI images
var S2_2 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterBounds(geometry)
.filterDate('2018-10-24','2019-06-30')
.filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE',20))
.map(ndvi2);
print('S2 NDVI ImageCollection',S2_2);
// Combine S2_1 and S2_2 Image Collections using Date
// Specify the join type
var join_type = ee.Join.inner();
// Set the join parameter
var filter = ee.Filter.equals({
leftField: 'Date',
rightField: 'Date'
});
// Execute the join
var inner_join = ee.ImageCollection(join_type.apply(S2_1,S2_2,filter));
// Flatten joined images into a single image with 2 bands
var S2_Combined = inner_join.map(function(feature) {
return ee.Image.cat(feature.get('primary'), feature.get('secondary'));
});
print('Combined S2 Collection:',S2_Combined);