Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
image_expression_null_value_handling [2022/08/20 19:24]
admin
image_expression_null_value_handling [2022/08/20 19:45]
admin
Line 32: Line 32:
 The  null evaluation mechanism allows us to write short expressions like ''​i1 + 10''​ to add 10 to every //valid cell// of the ''​i1''​ map, or ''​i1 * i2''​ to  multiply two maps. If one of the map cells is null, the result is null, so in the last example, we are basically just multiplying the corresponding cells where the  two values are valid: **everything else will be null**. The  null evaluation mechanism allows us to write short expressions like ''​i1 + 10''​ to add 10 to every //valid cell// of the ''​i1''​ map, or ''​i1 * i2''​ to  multiply two maps. If one of the map cells is null, the result is null, so in the last example, we are basically just multiplying the corresponding cells where the  two values are valid: **everything else will be null**.
  
-If we  want to treat all null values as values 1s, in the previous expression, we can write ''​(i1 ? 1) * (i2 ? 1)''​. We can also use the more complicated form using the ''​if then else''​ to achieve the same result:  +If we  want to treat all null values as values 1s, in the previous expression, we can write ''​(i1 ? 1) * (i2 ? 1)''​. We can also use the more complicated form using the ''​if then else''​ to achieve the same result ​such as ''​(if isnull(i1) then 1 else i1) * (if isnull(i2) then 1 else i2)'',​ or even 
-  * ''​(if isnull(i1) then 1 else i1) * (if isnull(i2) then 1 else i2)'',​ +  if isnull(i1) and isnull(i2) then 1 
-or +  ​else if not isnull(i1) and not isnull(i2) then i1*i2 
-''​if isnull(i1) and isnull(i2) then 1 +  ​else if not isnull(i1) and isnull(i2) then i1 
-else  if not isnull(i1) and not isnull(i2) then i1*i2 +  else i2
-else  if not isnull(i1) and isnull(i2) then i1 +
-else  if isnull(i1) and not isnull(i2) then i2''​+
  
 If you need to retrieve the number corresponding to a image null value, you can use the ''​null( iX )''​ expression. For instance, ''​null(i1)''​ returns the number corresponding to the null value of image ''​i1''​. So if, so some reason, you need to retrieve the image value or its corresponding numeric null value, you can use ''​i1 ? null(i1)''​ or ''​if isnull(i1) then null(i1) then i1''​. Note that ''​null(i1)''​ is very different from expression ''​null'',​ since ''​null(i1)''​ always returns a valid numeric value and ''​null''​ returns a special construct that, if not contained, invalidates the expression evaluation producing null as a result. If you need to retrieve the number corresponding to a image null value, you can use the ''​null( iX )''​ expression. For instance, ''​null(i1)''​ returns the number corresponding to the null value of image ''​i1''​. So if, so some reason, you need to retrieve the image value or its corresponding numeric null value, you can use ''​i1 ? null(i1)''​ or ''​if isnull(i1) then null(i1) then i1''​. Note that ''​null(i1)''​ is very different from expression ''​null'',​ since ''​null(i1)''​ always returns a valid numeric value and ''​null''​ returns a special construct that, if not contained, invalidates the expression evaluation producing null as a result.