A modular land cover system part 1
Step 1: Create a new repository and call it mrc.
Step 2: create a new script and call it importS2_module
Step 3: copy the code below and store it in the script
var inBands = ee.List(['QA60','B1','B2','B3','B4','B5','B6','B7','B8','B8A','B9','B10','B11','B12']); var outBands = ee.List(['QA60','cb','blue','green','red','re1','re2','re3','nir','re4','waterVapor','cirrus','swir1','swir2']); var CloudCoverMax = ?? exports.importData = function(studyArea,startDate,endDate) { // Get Sentinel-2 data var s2s = ee.ImageCollection('COPERNICUS/S2') .filterDate(startDate,endDate) .filterBounds(studyArea) .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',CloudCoverMax)) .filter(ee.Filter.lt('CLOUD_COVERAGE_ASSESSMENT',CloudCoverMax)); function scaleBands(img){ var prop = img.toDictionary() var t = img.select(['B1','B2','B3','B4','B5','B6','B7','B8','B8A','B9','B10','B11','B12']).divide(10000); t = t.addBands(img.select(['QA60'])).set(prop).copyProperties(img,['system:time_start','system:footprint']) return ee.Image(t); } s2s = s2s.map(scaleBands); s2s = s2s.select(inBands,outBands) ; return s2s; };
Step 4: Create a new script and call it main
// import required modules var importS2 = require("users/../mrc:importS2_module"); // import shapefile data var cambodia = ee.FeatureCollection("users/.../.../KHM_adm1"); var KampongThum = cambodia.filter(ee.Filter.eq("NAME_1","...")).geometry(); // set the variables var CloudCoverMax = ...; var startDate = ...; var endDate = ...; var studyArea = ...; print("getting images"); var s2 = importS2.importData(studyArea,startDate,endDate); print("found ",s2.size(),"images"); Map.addLayer(ee.Image(s2.first()),{min:0,max:0.6,bands:"swir2,nir,red"},"first image"); print(ee.Image(s2.first()));
Step 5: Run the script
Hi, thank you for this material, I’m learning a lot from that. I’m trying this series #1-#6 but I have a problem on the first part of the script.
I’m changing the studyArea with mine parameters, I tried with many, and every time the maps displayed are a small ” trapezium” outside the area I choose for analysis, it has the same shape of your study area. What’s causing that?
can you share an example?
Thank you for your reply, sure I can. Here the link: https://code.earthengine.google.com/ed1ae0ff37ac74f365aee1bc4f7eb7da
Even in your script if I remove variables “var Cambodia” and “var KampongThum” and instead I draw a square for studyArea it will still show the map as the old variables were there, I think the problem is inside “importS2_module” but I can’t find it.
I look forward to check your other posts,
Alex
It shows the first image in your collection. the composite shows the median of all images.. but takes time to calculate. You could export it. you also might want to review the parameters in the cloud and shadow modules..
Ok thank you so much for your fast reply. So I’ll try to export the composite and using it following your classification post! About the cloud parameters, Why did you choose to keep this parameter editable other script and not only in “main”? I mean, I can be wrong and set 3 different values in each script.