Google Earth Engine – Export Specific Multiband Image of Sentinel-2

exportgoogle-earth-enginegoogle-earth-engine-javascript-api

I am interested in removing cloud in https://code.earthengine.google.com/d9aaa276f0fa1ab33e78230e8f348c6f.
I try to export specific multiband to GDrive in GEE. I try to write the sintax :

Export.image.toDrive({
   image: s2_sr_median,
   description: 'image_export',
   folder: 'ee_demos',
   region: region,
   scale: 10,
   crs: 'EPSG:4326'
   });

But, the result all band will be exported. So, how to export specific multiband, for example band 2,3,4, and band 8. I have try this sintax, but not successfull. There is a message : Line 123: Unexpected arguments to function toDrive(): band.

Export.image.toDrive({
   image: s2_sr_median,
   description: 'image_export',
   folder: 'ee_demos',
   band: ['B2', 'B3', 'B4', 'B8'],
   region: region,
   scale: 10,
   crs: 'EPSG:4326'
   });

So, how is the solution ?

Best Answer

You can select() the bands after doing the median(). You can do it in two ways. Either you can use the index of the bands starting from 0.

var s2_sr_median = (s2_sr_cld_col.map(add_cld_shdw_mask)
                             .map(apply_cld_shdw_mask)
                             .median()).select([1,2,3,7])

Or, if you do not want to go with the index, you can use the expression with band names. When the sequence breaks, put | between the band names.

var s2_sr_median = (s2_sr_cld_col.map(add_cld_shdw_mask)
                             .map(apply_cld_shdw_mask)
                             .median()).select('B[2-4]|B8')
Related Question