1

enter image description hereStarting from Global Hansen dataset and in particular lossyear map, with the following function I obtained an image collection. Each different image is given by the overlap of image for the current year and the image of the following year. These two maps are obtained following two different condition as report.

var mylist = ee.List.sequence(1, 16, 1);

var combine_img = ee.ImageCollection.fromImages(mylist.map(function(y) {    
  y = ee.Number(y).toInt();
  var a = gfc.select(['lossyear']).eq(y).rename('a'); //Current year
  var aP = gfc.select(['lossyear']).eq(y.add(1)).rename('aP'); //Next year
  var b = mapB.select(y.subtract(1)).rename('b');
  var bP = mapB.select(y).rename('bP');
  var c = mapC.select(y.subtract(1)).rename('c');
  // mapC is the discriminating factor.
  // In the map of following year I would like to have pixels that result by filtering for this map.

  var b_gt_bP = a.updateMask(b.gt(bP)).updateMask(c);
  // First condition
  // Values of map b  are greater than map bP
  // .gt mean "greater than".
  // Event in the current year

  var bP_lte_b = aP.updateMask(b.lte(bP)).updateMask(c);
  // Second condition
  // Values of bP map are greater than map b
  // .lte means "less than equals"
  // Event in the following year.


  return b_gt_bP.blend(bP_lte_b).set('imageNumber', y);
  // the first map is overlap to the other map.
  // Obtain a map with pixel value equal to imageNumber
}));

How can I modify this function to obtain not an image collection but a unique image? In this map the pixels values are equals to imageNumber?

EDIT: In my mind the pixel values have only integer number starting from 1 to 16.

picture

I attached a picture above. The image shows the proprieties of the first image that makes up my collection. The pixels in this image have value of 1. In my final map I want that these pixels have a value of 1 because it is referred to 2001. In the same map I would like also the pixels of other image of my collection that have a values between 2 to 16 according the year.

Here the code https://code.earthengine.google.com/b5594a0817fdd8c7483ca4906abf9eb9

2
  • Do you mean extract any image from the given collection? For instance,combine_img.first() will do the job. – Basile Mar 17 '20 at 19:21
  • I have tried this solution but it is not correct because if I understand the help well this function only uses the first band. I, on the other hand, would need a function that uses all bands. – matt85 Mar 18 '20 at 10:05
1

I think you're asking how to combine the single-band images in the image collection to a single, multi-band image. If so, you simply call ee.ImageCollection.toBands(). You might want to rename the generated band names to something cleaner. Here's an example how you could do that:

var gfc = ee.Image('UMD/hansen/global_forest_change_2018_v1_6');
var mapB = ee.Image('users/mattelearning85/mapB') //Harvest rate
var mapC = ee.Image('users/mattelearning85/mapC') //wind critical speed

var mylist = ee.List.sequence(1, 16, 1);
var combine_img = ee.ImageCollection.fromImages(mylist.map(function(y) {
  y = ee.Number(y).toInt();
  var a = gfc.select(['lossyear']).eq(y).rename('a'); //Current year
  var aP = gfc.select(['lossyear']).eq(y.add(1)).rename('aP'); //Next year
  var b = mapB.select(y.subtract(1)).rename('b');
  var bP = mapB.select(y).rename('bP');
  var c = mapC.select(y.subtract(1)).rename('c');
  var b_gt_bP = a.updateMask(b.gt(bP)).updateMask(c);
  var bP_lte_b = aP.updateMask(b.lte(bP)).updateMask(c);
  return b_gt_bP.blend(bP_lte_b).set('imageNumber', y)
    .rename(y.add(2000).format());
})).toBands().regexpRename('.*_(.*)', '$1')

print(combine_img)

https://code.earthengine.google.com/ae38f71938a11857f8aa1fcd4875de1e

6
  • Thanks for your answer @Daniel. I tried this solution but that's not what I'm looking for. I want in a single final map all the pixels that I would have in each of the different images. Each pixel has its own value which corresponds to the property in my function ad imageNumber. The final product that I expect is a map which in some ways is similar to the lossyear map of the hansen database. – matt85 Mar 18 '20 at 12:34
  • Sorry, but that's still not clear to me. The images in your collection contain values between 0 and 1, and each image represents one year. You want to reduce this image collection to a single image. Which bands do you want this image have - what should they contain? – Daniel Wiell Mar 18 '20 at 13:20
  • thanks you for the answer I'm trying to explain better my thinking. My final aim is to have a unique image which is made up of all the different images. I also want the pixel value that is now 1 to be equal to the year it refers to. The value I want for each pixels in the final image is equals to value of imageNumber property. If for example I consider a specific year, for example 2009 I would like that pixels that now have value of 1 have value of 9, – matt85 Mar 18 '20 at 15:14
  • But your values are floats between 0 and 1. If for instance a year have a value of 0.9, do you still want that year? Can multiple years have values, and if so, which year would you want? – Daniel Wiell Mar 18 '20 at 15:30
  • In my mind the pixel values have only integer number starting from 1 to 16. – matt85 Mar 18 '20 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.