// Get a feature collection of Thailand var c = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filter(ee.Filter.eq('country_na', 'Thailand')); // Map.addLayer(c); // ใช้ข้อมูลSentinel-2 var image = ee.ImageCollection('COPERNICUS/S2') //เปลี่ยนช่วงเวลาที่สนใจ .filterDate('2021-12-01', '2021-12-31') //filter according to drawn boundary .filterBounds(c); // Function to mask cloud from built-in quality band // information on cloud var maskcloud1 = function(image) { var QA60 = image.select(['QA60']); return image.updateMask(QA60.lt(1)); }; // Function to calculate and add an NDVI band var addNDVI = function(image) { return image.addBands(image.normalizedDifference(['B8', 'B4'])); }; // Add NDVI band to image collection var S2 = image.map(addNDVI); // Sentinel-2 Band var B = S2.median().select(['B2']); var G = S2.median().select(['B3']); var R = S2.median().select(['B4']); var NIR = S2.median().select(['B8']); var B11 = S2.median().select(['B11']); var B12 = S2.median().select(['B12']); // Extract NDVI band and create NDVI median composite image var NDVI = S2.median().normalizedDifference(['B8', 'B4']); var NDWI = S2.median().normalizedDifference(['B3', 'B8']); var RI = S2.median().expression( "(10**5)*((RED**2) / (BLUE * (RED**3)))", {'BLUE': B, 'RED': R, }); var SI = S2.median().expression( "(RED-BLUE) / RED ", {'BLUE': B, 'RED': R, }); var FI = S2.median().expression( "((2*RED)-GREEN-BLUE) / (GREEN-BLUE) ", {'BLUE': B, 'GREEN': G, 'RED': R, }); var SCI = S2.median().normalizedDifference(['B4', 'B3']); var BI = S2.median().expression( "sqrt((GREEN**2)+(RED**2)+(NIR**2)) / 10**4 ", {'NIR': NIR, 'GREEN': G, 'RED': R, }); var NDTI = S2.median().normalizedDifference(['B11', 'B12']); var STI = B11.divide(B12); // Create palettes for display var pal = [ '040274', '040281', '0502a3', '0502b8', '0502ce', '0502e6', '0602ff', '235cb1', '307ef3', '269db1', '30c8e2', '32d3ef', '3be285', '3ff38f', '86e26f', '3ae237', 'b5e22e', 'd6e21f', 'fff705', 'ffd611', 'ffb613', 'ff8b13', 'ff6e08', 'ff500d', 'ff0000', 'de0101', 'c21301', 'a71001', '911003']; // Set map center Map.centerObject(c, 6); //Display NDVI results on map Map.addLayer(NDVI.clip(c), {min:0.1, max:0.5, palette: pal}, 'NDVI'); Map.addLayer(NDWI.clip(c), {min:-1, max:0.5, palette: pal}, 'NDWI'); Map.addLayer(RI.clip(c), {min:0, max:0.5, palette: pal}, 'Redness Index'); Map.addLayer(SI.clip(c), {min:-0.5, max:0.5, palette: pal}, 'Saturate Index'); Map.addLayer(FI.clip(c), {min:0, max:10, palette: pal}, 'Form Index'); Map.addLayer(SCI.clip(c), {min:-0.5, max:0.5, palette: pal}, 'Soil Color Index'); Map.addLayer(BI.clip(c), {min:0, max:0.5, palette: pal}, 'Brightness Index'); Map.addLayer(NDTI.clip(c), {min:-0.2, max:0.5, palette: pal}, 'Normalized Difference Tillage Index'); Map.addLayer(STI.clip(c), {min:1, max:2, palette: pal}, 'Soil Tillage Index'); //Export data to your google drive //Export the NDVI, specifying scale and region. Export.image.toDrive({ image: NDVI, description: 'NDVI', scale: 10, region: c, maxPixels: 1e13, }); //Export the NDWI, specifying scale and region. Export.image.toDrive({ image: NDWI, description: 'NDWI', scale: 10, region: c, maxPixels: 1e13, }); //Export the RI, specifying scale and region. Export.image.toDrive({ image: RI, description: 'RI', scale: 20, region: c, maxPixels: 1e13, }); //Export the SI, specifying scale and region. Export.image.toDrive({ image: SI, description: 'SI', scale: 10, region: c, maxPixels: 1e13, }); //Export the FI, specifying scale and region. Export.image.toDrive({ image: FI, description: 'FI', scale: 10, region: c, maxPixels: 1e13, }); //Export the SCI, specifying scale and region. Export.image.toDrive({ image: SCI, description: 'SCI', scale: 10, region: c, maxPixels: 1e13, }); //Export the BI, specifying scale and region. Export.image.toDrive({ image: BI, description: 'BI', scale: 10, region: c, maxPixels: 1e13, }); //Export the NDTI, specifying scale and region. Export.image.toDrive({ image: NDTI, description: 'NDTI', scale: 20, region: c, maxPixels: 1e13, }); //Export the STI, specifying scale and region. Export.image.toDrive({ image: STI, description: 'STI', scale: 20, region: c, maxPixels: 1e13, });