MapInfo Pro

 View Only
  • 1.  MapInfo Monday: Overlay Analysis with the Raster Calculator

    Employee
    Posted 08-09-2021 06:49
    Happy #MapInfoMonday,​

    Today we will dive into another feature of MapInfo Pro Advanced that brings raster capabilities to MapInfo Pro. We will look at how you can use the Raster Calculator to locate where two, or more, conditions are met.

    Background

    In this example, we assume we have been doing a drive test to see how a telco network performs in a certain area. The drive test resulted in many measurements including a lat/long value. This test result has been used to create a raster grid. Please note this is not real drive test data but data I have generated manually.

    The other dataset is the traffic count taken from our StreetPro Traffic product which contains a relative traffic volume across all hours on weekdays and weekends. I have summarized the traffic volumes for weekdays and used this to illustrate an expected traffic volume. Finally, I used one of the interpolation methods of MapInfo Pro Advanced to create a raster grid from all the road segments.

    In the image below, you can see two maps. The map on the left shows the drive test result where yellow represents low values and blue high values. The map on the right shows the traffic volume where red represents high volumes of traffic and light yellow low volumes. In the map on the right, you can clearly see that highways have a higher amount of traffic compared to smaller local roads.

    I have also added a purple polygon in both maps to show the drive test area southeast of Birmingham.

    Finding locations where the conditions are met

    The next step is to use the Raster Calculator to analyze the two raster grids. You can open the Raster Calculator from the Raster Operations dropdown on the Raster tab.

    The Raster Calculator appears in a panel typically on the right side of your MapInfo Pro window.

    In the Input section of the Calculator panel, click the New button, rename the new input to "DriveTest" and select the raster grid containing the DriveTest data.

    Now click the New button again in the Input section, rename it to "Traffic", and select the raster grid containing the traffic data.

    You have now created two input variables that we can use in the Expression builder above.

    Expand the Expressions dropdown, and select the expression Keep If < variable. Now modify the expression from the standard version:
    cond(Input_1 < Variable_1; Input_1; null)
    to our version:
    cond(DriveTest < 20; ; null)
    where DriveTest is our input raster grid and 20 is the threshold we are comparing the values in the raster grid to. If the value is bigger than or equal to 20, the value for the grid cell will be assigned the value of NULL. This means we are only interested in the grid cells with values lower than 20.

    Now position the cursor between the two comma separators as we want to insert another expression here. From the Expression dropdown, select the expression Keep If > variable. And again we need to modify the final expression slightly from 
    cond(DriveTest < 20; cond(Input_1 > Variable_1; Input_1; null); null)
    to our version:
    cond(DriveTest < 20; cond(Traffic > 1000; ; null); null)
    This time we compare the values from the raster grid Traffic to the value 1000. The second condition we just added will only be considered when the value from the DriveTest raster grid is less than 20. In this case, we will compare the value for the matching cell in the Traffic grid to our threshold of 1000. If the value is less than 1000, a NULL value will be assigned to the grid. This means that even though the telco coverage isn't too good at this location, it might not matter that much as there isn't that much traffic here either.

    Finally, we need to specify the return value if both our conditions are met. Typically this would be the value from one of the input raster grids. In our case, we will return the value from the DriveTest grid. Notice that you can either select the Input from the Input section and use the Insert button to insert in the Expression area, or you can type it manually. After typing a few characters, you can use Ctrl+Space to activate Intellisense to show you matching values. In the example below, you can see it presents me with the option "DriveTime". I can select this using my mouse or simply by hitting Enter on the keyboard.

    The final expression looks like this:
    cond(DriveTest < 20; cond(Traffic > 1000; DriveTest; null); null)

    The last thing we want to change is the name of the output raster grid. IN the Output field you can enter a descriptive name for the output raster file. You can also use the Browse button to select a different location for the output raster file, and even change the raster format to a format different from MRR.

    Hit the Compute button to let the Raster Calculator run your expression. As the raster grids in my example are quite small, the process takes very little time. In the Task window, you can see it finished after 1.1 seconds.

    The resulting raster grid has been opened into one of my existing map windows. To get a clearer view of the result, I select the raster grid in the Layers List, and from the Style tab and change the Color Template used for the raster grid.

    Zooming in on a specific area clearly shows some issues. It seems that the values from the Drive Test raster grid generally are low in this area, and when comparing this to high traffic values, we can see some potential issues stand out in red in the left map window.

    I hope this has given you some ideas on how you can use the Raster Calculator of MapInfo Pro Advanced to easily compare values across two or more raster grids.

    A piece of small bonus information: I can tell you that I used the Sync Windows tool to keep the two map windows in sync. You can find this tool in the Tools window.

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


  • 2.  RE: MapInfo Monday: Overlay Analysis with the Raster Calculator

    Posted 08-10-2021 20:17
    Hi Peter,

    The calculator expression "cond(a,b,c)" is a programmer-friendly way of writing "IF (condition a) THEN (result b) ELSE (result c)" expression.
    Two observations -

    Firstly, you have used a nested "cond" command to test two variables. It would be simpler to just use a logical "and" operator.

    Secondly, it is a little-known fact that you can use an IF - THEN - ELSE - ENDIF syntax instead of a "cond" command in the calculator, which may be easier for users to comprehend.

    So, your expression "cond(DriveTest < 20; cond(Traffic > 1000; DriveTest; null); null)" could be expressed in two other ways in the calculator - 

    cond(DriveTest < 20 and Traffic > 1000; DriveTest; null)

    or - 

    IF DriveTest<20 and Traffic>1000 THEN DriveTest ELSE null ENDIF

    Don't forget there is a "Validate" button in the calculator that you can press to see if your expression syntax is correct.



    ------------------------------
    Sam Roberts
    Founder, Roberts Geospatial Engineering
    Australia
    ------------------------------



  • 3.  RE: MapInfo Monday: Overlay Analysis with the Raster Calculator

    Employee
    Posted 08-11-2021 02:55
    Thanks, Sam.

    Some good additional information in your post, and I really like your more simplistic expression. Not sure why I didn't think of that.

    And thanks for highlighting the option to use IF THEN ENDIF. That was new to me too.

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