2

Code link: https://code.earthengine.google.com/a2c5293fff598d37ccb7843bff8bc27d

In this expression, the value of 'E' is derived from the image. All other values come from the asset table. So I wanted to use if/else in this code:

If 'E' is greater than 0.78, it uses 'A', 'B', 'C', 'D' value defined in expression. Else if it is smaller than 0.78, it uses different 'A', 'B', 'C', 'D' value.

I created the expression code but don't now how to use if/else statement for the expression.

var aqi = image.expression
('((A-B)/(C-D))*(E-D)+B'
, { 
  'A': ee.Number.parse(table.filter(ee.Filter.eq('No2', 10)).first().get('No2')),
 'B': ee.Number.parse(table.filter(ee.Filter.eq('No2', 40)).first().get('No2')),
  'C':ee.Number.parse(table.filter(ee.Filter.eq('No2', 50)).first().get('No2')),
  'D':ee.Number.parse(table.filter(ee.Filter.eq('No2', 80)).first().get('No2')),
  'E':image.select('NO2_column_number_density').multiply(1000),

1 Answer 1

1

You don't do it with an if, you do it by computing both and selecting one vs the other with a where() statement.

result1 = image.expression('(A1-B1) / (C1-D1)...')
result2 = image2.expression('(A2 - B2) / (C2-D2)...')
result = result1.where(e.lt(0.78), result2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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