I am trying to make a random forest classifier for mangroves on an island in the Philippines. I have already produced the desired outcome for dates in 2019 using exactly the same code, but I need the dates changed to ones in December 2021.
// cloud filtering
function maskS2clouds(image) {
var cloudBitMask = ee.Number(2).pow(10).int();
var cirrusBitMask = ee.Number(2).pow(11).int();
var qa = image.select('QA60');
var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask);
}
// rename bands
function renameS2bands(image){
return image.rename('B', 'G', 'R', 'NIR', 'SWIR', 'SWIR2', 'QA60')
}
// load Sentinel-2 TOA reflectance data.
var s2collection = ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED")
.filterDate('2021-10-01', '2021-12-15')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
.filterBounds(geometry)
.select('B2', 'B3', 'B4', 'B8', 'B11', 'B12', 'QA60')
.map(maskS2clouds)
.map(renameS2bands);
//Reduce the first collection (median reducer in this case)
var s2_median = s2collection.median()
// load the pre-computed Sentinel-2 composite as input
var input = s2_median;
// define a region in which to generate a sample of the input
var region = geometry;
// make the training dataset
var training = input.sample({
region: region,
scale: 20,
numPixels: 40
});
// print training (feature collection)
print(training)
The error is: FeatureCollection (Error) Image.sample: Unable to find a crs.
My geometry variable is a geometry drawn around an island in the Philippines. Any help would be much appreciated.