Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function addMask(img){
- // grabbing the attached image
- var fmask_img = img.get('fmask');
- // Trying to access a band in the original image works
- //var b1 = img.select(["B1"]);
- // Trying to access a band in the image doesn't work
- //var fmask = fmask_img.select(["fmask"]);
- //trying to add a band from the attached image to the orignal image doesn't work
- //var newImg = img.addBands(fmask_img, ["fmask"])
- //trying to all bands from the attached image to the orignal image also doesn't work
- //var newImg = img.addBands(fmask_img, ["fmask"])
- //even trying to the origianl image to is self doesn't work
- //var newImg = img.addBands(img)
- return img // returning the unchanged image instead of newImg
- }
- // Load a primary collection: Landsat imagery.
- var primary = ee.ImageCollection('LC8_L1T')
- .filterDate('2014-04-01', '2014-06-01')
- .filterBounds(ee.Geometry.Point(-122.092, 37.42));
- // Load a secondary collection: MODIS imagery.
- var secondary = ee.ImageCollection('LANDSAT/LC8_L1T_TOA_FMASK')
- .filterDate('2014-04-01', '2014-06-01')
- .filterBounds(ee.Geometry.Point(-122.092, 37.42));
- // Create a filter to define a match based on the scene ID.
- var sceneFilter = ee.Filter.equals({
- leftField: "LANDSAT_SCENE_ID",
- rightField: "LANDSAT_SCENE_ID"
- })
- // Define the join.
- var saveFirstJoin = ee.Join.saveFirst({
- matchKey: 'fmask',
- ordering: 'system:time_start',
- ascending: true
- });
- // Apply the join.
- // This returns an image collection
- var landsatFmask = saveFirstJoin.apply(primary, secondary, sceneFilter);
- // Mapping a simple function where input = output returns an image collection
- var fmask = landsatFmask.map(addMask);
- // applying a reducer on the orignal collection works
- var primary_median = primary.median()
- //applying a reducer on the orignalnew collection works doesn't work
- //var fmask_median = fmask.median()
- //var joined_median = landsatFmask.median()
- // Display the result.
- // the orginal collection
- print('raw:', primary)
- // looks the same as the orginal, only difference is that images inside the collection have an additional property "fmask" with the joined image inside
- print('Join.saveAll:', landsatFmask);
- // looks the same as the joined collection, but now the band list of the images collection is empty ??
- print('fmask:', fmask);
- function addMask(img){
- // cast the input image
- var i = ee.Image(img);
- // grabbing the attached image and cast it as well
- var fmask_img = ee.Image(img.get('fmask'));
- //now i can add the band
- var newImg = i.addBands(fmask_img, ["fmask"])
- return newImg
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement