I have this situation on Google Earth Engine: 3 different images, each of these are made by 17 different bands. These bands represent the different year. I call these images with these letter: a,b and c. Image c is a binary map (1, no data). I would like to have a map that answer to this condition:

if b > b+1= a(b∩c) else a+1(b+1∩c)

for example if the values of a band of 2000 are major than 2001 the map respect this condition else l'altra. I consider only the year and the next year (2000-2001,2002-2003 ....)

So I would if the condition is true the only pixel of a or a+1 image that respect the intersect condition. I did some tests using only 3 bands (one per image) and I identified this possible solution in this command:


But how I can do for respect my condition?

I think to an expression as the following code:

a.expression(‘?b>b+1=a.updateMask(b).update(c): a+1.updateMask(b).updateMask(c)’,
{‘a’:a.select(),‘b’:b.select(),‘c’: c.select() })

I obtain this error message:

Image (Error)
Image.parseExpression: Expression parse error at character 0:
'? b(y)>b(y+1) = a(y).updateMask(b(y)).updateMask(c(y)):  a(y+1).updateMask(b(y+1)).updateMask(c(y))'

Where am I doing wrong?


Your expression is not stated well. With access to the assets, this seems to be a fast solution:

var list = ee.List.sequence(0,15,1);
var mapA = ee.Image('users/mattelearning85/mapA');
var mapB = ee.Image('users/mattelearning85/mapB');
var mapC = ee.Image('users/mattelearning85/mapC');
var mapC ee.Image('users/mattelearning85/mapC').select(['b1','b2','b3','b4','b5','b6','b7','b8','b9','b10','b11','b12','b13','b14','b15','b16','b17','b18'], ['b0','b1','b2','b3','b4','b5','b6','b7','b8','b9','b10','b11','b12','b13','b14','b15','b16','b17'])

var images = ee.ImageCollection.fromImages(list.map(function(y) {
  y = ee.Number(y).toInt();
  var a = mapA.select(y).rename('a');
  var a1 = mapA.select(y.add(1)).rename('a1');
  var b = mapB.select(y).rename('b');
  var b1 = mapB.select(y.add(1)).rename('b1');
  var c = mapC.select(y).rename('c');

  var b_gt_b1 = a.updateMask(b.gt(b1)).updateMask(b).updateMask(c);
  var b1_lte_b = a1.updateMask(b.lte(b1)).updateMask(b).updateMask(c);

  return b_gt_b1.blend(b1_lte_b).set('imageNumber', y);



  • Sorry, the assets are public now (I think) here the script following your indications code.earthengine.google.com/91e0b060559ee7f083912a4b84dba25b the script function but in b1_lte_b image should not I use the image a1? – matt85 Jan 12 '19 at 8:14
  • Yes it needed to be a1. Thanks for giving the access. I updated the answer. I guess you will need blend instead of add, as otherwise all masked pixels will be omitted. – Kuik Jan 12 '19 at 8:57
  • thank a lot for your help, sorry for my delate. I found some errors into start data in particular for map C. Following your suggestion I introduce some little device to to the script (I update the script). why the use of blend function? – matt85 Jan 16 '19 at 19:27

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.