Conditional expressions in Raster Calculator

CorsabrinCorsabrin Global Mapper UserPosts: 29
edited June 2015 in Technical Support
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:


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



  • JeffH@BMGJeffH@BMG Global Mapper Developer Posts: 337Trusted User
    edited June 2015
    Hello Corse,

    AND 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,

  • CorsabrinCorsabrin Global Mapper User Posts: 29
    edited June 2015
    thanks for the reply Jeff, it helped me greatly. Could I check, if there is any documentation pertaining to using the raster calculator in GM? This is because I couldn't find anything related to usage of AND or other possible formula structures in GM
  • JeffH@BMGJeffH@BMG Global Mapper Developer Posts: 337Trusted User
    edited June 2015
    Hi Corse,

    Hmmm, 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.

    • Numbers - Here are some examples of numbers:
      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):
      red or R: Red band
      green or G: Green band
      blue or B: Blue band
      B#, where # is an integer greater than zero: a numbered band, e.g., B3
      elev or Z: 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):
    • 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.
    You may also use parentheses to specify order of operations. In the absence of parentheses, higher precedence operations are performed before lower precedence operations. That is, in the formula "B1 + r * 3", the result is the value of 'B1' plus the product of 'r' and '3' (equivalently "B1 + (r * 3)").


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

    • LOG( 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 expression3

    Hope that this helps.

    Best regards,


Sign In or Register to comment.