I am trying to reduce the resolution of 10m bands (B2-4,B8) to 20m resolution so that I have uniform resolution for all bands I want to use. I tried a solution provided by Jepson Nomad for similar question. I tried to write a function so that I can apply it to image collection. But its not working as no change in resolution is happening like in Jepson's solution. How can I change the resolution to 20m?
var s2= ee.ImageCollection("COPERNICUS/S2_SR").filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", 10));
var admin1 = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level1");
var MP = admin1.filter(ee.Filter.eq('ADM1_NAME', 'Madhya Pradesh'));
var geometry = MP.geometry();
////vis parameters.
var vis = {bands: ['B4', 'B3', 'B2'], max: 2000, gamma: 1.5};
////Define Study area
var area = ee.FeatureCollection(geometry);
var opacity = 0.5; // number [0-1]
Map.centerObject(area, 6.5);
////Filter Dates
var ImColA1 = ee.ImageCollection(s2.filterDate('2019-05-15', '2019-05-21') //// Filter by dates.
.filterBounds(area));
//////Masks/////
//// Creat a Cloud Mask.
function maskS2sr(image) {
var cloudBitMask = ee.Number(2).pow(10).int(); ////cloud band
var cirrusBitMask = ee.Number(2).pow(11).int();//// cirrus band
var qa = image.select('QA60'); //// Get the pixel QA band.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0) //// Flags set to zero for clear conditions.
.and(qa.bitwiseAnd(cirrusBitMask).eq(0)); //// Flags set to zero for clear conditions.
return image.updateMask(mask) //// Return the masked image, scaled to TOA reflectance, without the QA bands.
.copyProperties(image, ["system:time_start"]);
}
////Add masks
var CM_ImColA1 = ImColA1.map(maskS2sr)
print(CM_ImColA1);
/////Resampling/////
var resample20 = function(image){
var projection =image.select('B12').projection();
var bands = image.select('B[2-4]','B8','B8A','B11','B12');
var resample = image.reproject({
crs: projection,
scale: 20
});
return bands
.copyProperties(image,['system:time_start','system:time_end']);
};
var resmap_CM_ImColA1 = CM_ImColA1.map(resample20);
print(resmap_CM_ImColA1);
///////Mosaic and Clip//////
var mosA1 = CM_ImColA1.mosaic().clip(area);
var mosA2 = resmap_CM_ImColA1.mosaic().clip(area);
Map.addLayer(mosA1, vis,'MosaicA1');
Map.addLayer(mosA2, vis,'MosaicA2');