# Conditional expressions in Raster Calculator

Corsabrin
Global Mapper UserPosts:

**29**
Hi there

I would like to reclassify my slope map into various bins (e.g. 0 to 5 degrees -> bin no. 1 and so on). To do this, I attempted to use the raster calculator but I realised I had to use conditional expressions to do this:

So I typed:

IF(AND(B1>=0,B1<=5),1,0)

But GM gave me an error saying that it cannot recognise the expression "and". I tried to look around for information regarding conditional syntax in GM, but wasn't able to find any help on that.

Anyone has any idea how should this be corrected? Or if there is any workaround on that?

Using GM v16

Regards

Corse

I would like to reclassify my slope map into various bins (e.g. 0 to 5 degrees -> bin no. 1 and so on). To do this, I attempted to use the raster calculator but I realised I had to use conditional expressions to do this:

So I typed:

IF(AND(B1>=0,B1<=5),1,0)

But GM gave me an error saying that it cannot recognise the expression "and". I tried to look around for information regarding conditional syntax in GM, but wasn't able to find any help on that.

Anyone has any idea how should this be corrected? Or if there is any workaround on that?

Using GM v16

Regards

Corse

## Comments

337Trusted UserAND is not a function (like IF() or MAX()); it's an operator like + or =. The correct syntax for the formula that you posted would be:

IF( B1>=0 AND B1<=5, 1, 0 )

best regards,

~Jeff

29337Trusted UserHmmm, looks like our online help is somehow out of date, at least with respect to that subject. I'm not sure why that is, so I'll need to track that down. In the meantime, I'll just post the bit that should be there:

Custom Formula Reference

Custom Formulas allow you to generate new bands for a raster image based on formulas that are not already predefined in Global Mapper. Formulas are mathematical expressions that can combine numbers, band values, or elevations to compute new band values. They may use standard mathematical operators like +, -, *, /, ^ (power), comparison and relational operators, and functions like LOG, LOG10, MIN, and MAX to produce new values.OperandsNumbers- Here are some examples of numbers:3.14159

42

1234e-3 (scientific notation; the result is 1.234)

123,456 (European notation; the result is 123.456)

Band values- Band values refer to a specific raster band in an image. Allowable band references (again, the names below are case-insensitive):redorR: Red bandgreenorG: Green bandblueorB: Blue bandB#, where # is an integer greater than zero: a numbered band, e.g.,B3elevorZ: Elevation pseudo-band for use with terrain layers (in which case, B1 is equivalent)

Formulas use various mathematical and logical operators to form a result, similar to spreadsheet formulas. They are (in order of precedence, low-to-high):Operators

OR: logical OR: both operands are treated as boolean values and a boolean value is returned (1 if either of the operands are non-zero, or 0 otherwise).AND: logical AND: both operands are treated as boolean values, snd a boolean value is returned (1 if both of the operands are non-zero, or 0 otherwise).=, <>, ~=: comparison operators: equals, not equals, and case-insensitive string comparison, respectively.<, <=, >, >=: relational operators: less than, less than or equal to, greater than, and greater than or equal to, respectively.+, -: additive operators: plus and minus, respectively.*, /: multiplicative operators: times and divide, respectively. The operands are assumed to be numeric.^: exponentiation+, -, NOT: unary operators: plus, minus, and logical NOT respectively. The operands for unary plus and minus are assumed to be numeric; the operand for unary NOT is assumed to be boolean.Functions

The calculator provides several built-in functions to aid in calculation of values. Note that function names are case-insensitive; that is,

logis the same asLOGLOG( expression ): Natural logarithm. The expression parameter is assumed to be a numeric value.LOG10( expression ): Base 10 logarithm. The expression parameter is assumed to be a numeric value.MAX( expression1, expression2 ): Maximum value of a expression1 and expression2.MIN( expression1, expression2 ): Minimum value of a expression1 and expression2.IF( expression, expression2, expression3 ): Evaluate expression, and if it is true, return expression2; otherwise return expression3Hope that this helps.

Best regards,

~Jeff