var Train =
/* color: #d63000 */
/* shown: false */
ee.Geometry.Polygon(
[[[11.404322420267174, 46.32569478725022],
[11.402605806497643, 46.2198529823167],
[11.66559103598983, 46.28537560568817],
[11.648081575540612, 46.34489524610421]]]),
sentinel2 = ee.ImageCollection("COPERNICUS/S2_SR"),
ROI = ee.FeatureCollection("projects/ee-matteogiomo04/assets/TEST_SET"),
visParamsTrue = {"bands":["B4","B3","B2"],"min":0,"max":2500,"gamma":1.1};
// 1) Set some parameters
var start1 = ee.Date('2018-06-01')
var end1 = ee.Date('2018-07-30')
var ROI = ee.FeatureCollection(ROI).geometry()
print(ROI)
/////// FIRST ROUGH METHOD /////////
var image = sentinel2
.filterDate(start1, end1)
.filterBounds(Train)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
.filter(ee.Filter.lt('DARK_FEATURES_PERCENTAGE', 20))
.filter(ee.Filter.lt('CLOUD_SHADOW_PERCENTAGE', 20))
.filter(ee.Filter.lt('MEAN_SOLAR_ZENITH_ANGLE', 30));
print('Less cloudy', image)
Map.addLayer(ROI, {}, 'Test Area');
Map.addLayer(image, visParamsTrue, 'Rough');
Map.setOptions('SATELLITE');
Map.centerObject(Train, 12);
///////// AUTOMATIC METHOD /////////
var images = sentinel2.filterBounds(ROI.centroid()); // filter in the centroid of the ROI
function calcCloudStats(img) {
var imgPoly = ee.Algorithms.GeometryConstructors.Polygon(
ee.Geometry( img.get('system:footprint') ).coordinates()
)
var intersection = ROI.intersection(imgPoly, ee.ErrorMargin(0.5))
var areaImg = img.select('QA60').multiply(ee.Image.pixelArea())
var stats = areaImg.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: ROI,
scale: 10,
maxPixels: 1e9
})
var cloudPercent = ee.Number(stats.get('QA60')).divide(imgPoly.area())
var coveragePercent = ee.Number(intersection.area()).divide(ROI.area())
var cloudPercentROI = ee.Number(stats.get('QA60')).divide(ROI.area())
img=img.set('1_CLOUDY_PERCENTAGE', cloudPercent)
img=img.set('2_ROI_COVERAGE_PERCENT', coveragePercent)
img=img.set('3_CLOUDY_PERCENTAGE_ROI', cloudPercentROI)
return(img)
}
var cloudIndexes = images.map(calcCloudStats)
var image1 = cloudIndexes
.filterDate(start1, end1)
.sort('3_CLOUDY_PERCENTAGE_ROI')
.first();
Map.addLayer(image1, visParamsTrue, 'Automatic');
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user