MapInfo Pro

 View Only

MapInfo Monday: Using the Any operator in the Raster Calculator

  • 1.  MapInfo Monday: Using the Any operator in the Raster Calculator

    Employee
    Posted 08-01-2022 05:18
    Happy #MapInfoMonday!

    In today's article, I'll show you how you can take advantage of the any operator when querying your raster data through the Raster Calculator.​

    With the Raster Calculator, you can query out cells from your raster that meets a certain condition. Maybe you are looking for a specific value, values that are lower or higher than a given value, or maybe the value should be one of more possible values.

    In this example, I have a bathymetry dataset open that I want to query.

    First, I will open the Raster Calculator. I access it from the Raster Operations gally on the Raster tab.

    When I click the Raster control in the gally, the Calculator window opens up, typically on the right side of the MapInfo Pro window.

    I always start by creating a new input that will refer to the input raster I want to query. Click the New button under Inputs. This will add a new input with the Alias "Input_1". You can rename this to something more meaning full if you prefer. The option to rename is especially useful if you are querying multiple raster files.

    Now make sure the selected raster in the Raster list is the one you are looking to query.

    To get started, I'll insert a Common Expression into the Expression Editor, the area where you write your expressions. I select the expression Keep if = variable as I think that is a close match to what I'm looking for.

    The expression I inserted looks like this:
    cond(Input_1 = Variable_1; Input_1; null)

    Let me just walk you through this before modifying it.
    • cond(): a function that takes a condition and returns one of two possible results.
    • Input_1: refers to the input alias I created earlier.
    • Variable_1: is similar to an input alias but refers to a value instead of a raster.
    The expression basically states: if the value in a cell in your raster is equal to the value in the variable, return that value, otherwise return NULL.

    This is a very straightforward expression that can be used to create a new raster where all the values are of the value specified.

    We are looking to enhance this a bit as we are looking for an interval of values, not just one specific value. Instead of using the = operator, we will use the any operator.

    First, we modify the expression to use the other approach and remove Variable_1 from the expression.
    cond(any(Input_1; ); Input_1; null)

    Any is in fact a function and not an operator: From the Help System:
    Use Any function to match against a collection/range of values. Returns TRUE (1) if the Raster Cell Value matches with the specified collection or range. Each argument can either be a numeric value, or a range specified as n1..n2 or n1:n2, where n1 and n2 are real numbers. For example, cond(Any(Input_1, 22, 100 200..300, 500:600), Input_1, null).

    The next step is to incorporate the use of Any in my expression. I'm looking for the cells that are at the depth between 4 and 5 meters. Do note that the values in my bathymetry data are negative:
    cond(any(Input_1; -5:-4); Input_1; null)

    I can also look for multiple intervals in my raster using an expression like this:
    cond(any(Input_1; -5:-4; -1:0); Input_1; null)

    In my examples above, I have looked for specific intervals. Another use case for this method is when you are looking for a specific value but you want to add some threshold to the condition as with floating values, it can be almost impossible to find the exact value. Say you are looking for cells where the value is 1. But you know that the values in the cells might be slightly off from this. You can then search for values that are between 0.99 and 1.01 as an example:
    cond(any(Input_1; 0.99:1.01); Input_1; null)

    A final word about the expression builder for the Raster Calculator. It's important to note that the separators that you have to use, are based on your regional settings. I'm using the regional settings for Denmark. This means that the List Separator is a semicolon ( ;). For most English users, this separator will be a comma ( ,).

    I hope you found this useful.

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------