Pitney Bowes
MapInfo Pro™ Monthly Journal
Get on the Grid: Intro to the Calculator

Esther The Calculator in MapInfo Pro Advanced provides a powerful tool for performing multiple tasks on an input raster file or multiple raster files. You can perform mathematical calculations using operators and functions or set up selection queries. Inputs can be in Multi-Resolution Raster (.mrr) format or other supported formats.

In this article, we will show examples of using the Calculator on a numeric grid, a classified grid and on both grids at the same time. For a refresher on classified vs numeric grids, click here.

Numeric grid

In this example, we will use a Vertical Mapper numeric grid, SeattleElevation.grd.


SeattleElevation.grd from Vertical Mapper® Tutorial Data.

We will use the Calculator to select areas with elevation below 5 metres, and output the result to a new grid.



Drop down the Common Expressions menu and select "Keep if < variable" to keep values in the SeattleElevation.grd if they are less than 5 metres.



The following expression: cond(Input_1 < Variable_1, Input_1, null) will be entered into the Expression Editor.


The cond function is used to perform conditional tests. The syntax is cond(logical_condition, value_if_true, value_if_false). Variable_1 value can be set in the Variables tab in the Calculator dialog.

Computing the output will return only areas with elevation below 5 metres as displayed below:



Classified grid

In this example, we will use a Vertical Mapper classified grid, SeattleLULC.grc.


SeattleLULC.grc from Vertical Mapper® Tutorial Data

This grid has 37 classes in total. We will use the Calculator to select only areas that are in the Urban or Built-up category, and output the result to a new grid.


The Classify tool can be used to view classes of a grid. The forward slash "/" is used to create a subcategory. This grouping can be viewed in the Statistics dialog (RASTER > Raster Statistics).

Either of the following expressions can be used:

cond(any(Input_1, "Urban or Built-up Land/Residential", "Urban or Built-up Land/Commercial and Services", "Urban or Built-up Land/Industrial", "Urban or Built-up Land/Transportation, Communications and Utilities", "Urban or Built-up Land/Industrial and Commercial Complexes", "Urban or Built-up Land/Mixed Urban or Built-up Land", "Urban or Built-up Land/Other Urban or Built-up Land"), Input_1, null)

OR

if any (Input_1, "Urban or Built-up Land/Residential", "Urban or Built-up Land/Commercial and Services", "Urban or Built-up Land/Industrial", "Urban or Built-up Land/Transportation, Communications and Utilities", "Urban or Built-up Land/Industrial and Commercial Complexes", "Urban or Built-up Land/Mixed Urban or Built-up Land", "Urban or Built-up Land/Other Urban or Built-up Land") then Input_1 else null endif

Using either expressions, classes in the Urban or Built-up Land category is true and will be returned while all other classes are false and set to null. Like the cond function, if returns a value if a condition is true and null if false. The addition of the any function is used to return a collection of classes. In this case, it returns true if the raster cell value matches the specified classes in the Urban or Built-up Land category.

Expression - Classified grid

You may begin to feel overwhelmed by the expressions above. Indeed, they can quickly become lengthy especially if more values are desired. To aid users, the save button can be utilised to save an expression in the Expression Editor to a location on one's computer for future use.

An alternative (less lengthy) expression can also be used to achieve the same result:

if (Input_1>="Urban or Built-up Land/Residential" & Input_1<="Urban or Built-up Land/Other Urban or Built-up Land") then Input_1 else null endif

This expression may look like a string comparison but internally in the Calculator, string values are pre-processed to class indexes before an expression is computed. Hence an expression like this will be based on numeric order of class indexes, and not alphabetical order.

Expression - Classified grid

As shown previously, the if ... then ... else ... endif structure can also be used interchangeably with the cond(i,ii,iii) structure. They are the same, but the first is perhaps clearer in simple cases. The latter i.e. cond((Input_1>="Urban or Built-up Land/Residential" & Input_1<="Urban or Built-up Land/Residential"),Input_1,null) is useful when you have nested conditions. Further details on syntaxes can be found under Raster Calculator Syntax in the Help file.

Using any of the expressions above will return only areas that are in the Urban or Built-up category as desired:

Output Classified Grid

Across two grids

We will now run a query on both output grids from the examples above to yield a grid with Urban or Built-up locations at risk of coastal flooding.

Drop down the Common Expressions menu and select "Keep first if second valid" to retain value from SeattleLULC_calc.grc if SeattleElevation_calc.grd is valid.

Keep first if second valid

The following expression: cond(Input_2 <> null, Input_1, null) will be entered into the Expression Editor. Select SeattleLULC_calc.grc as Input_1 and SeattleElevation_calc.grd as Input_2. As Input_1 i.e.SeattleLULC_calc.grc is the Primary Grid, the output type is Classified by default. This can be overridden if desired.

Expression - Across two Grids

The expression above yields a grid with Urban or Built-up locations at risk of coastal flooding:

Expression - Across two Grids

This final image shows both the input grids displayed together at the same zoom level with the elevation grid at 55% transparency:

Two Grids displayed

We have now been able to identify areas that are both Urban or Built-up and less than 5 metres above sea level to enable assessment of coastal flooding.

The Calculator can be applied to countless other use cases. A coal seam thickness grid can be multiplied by calorific value to return a grid showing economic product. Ratios on remotely sensed data can be used to reduce spectral differences caused by topographic slope and aspect, shadows or seasonal and daily changes in solar radiation angle and intensity. Ratios like the NDVI can also be used to provide unique information not available in any single band, useful for discriminating between features.

Do you have the latest version of MapInfo Pro?

If not, a free trial is available. The free trial includes the Advanced version.

Links to MapInfo Pro free trials in a number of languages can be found here: http://web.pb.com/mapinfopro-archive/resources

Article by Esther Kasinathan, Natural Resources Analyst
When not writing articles for "The MapInfo Pro" journal, Esther enjoys helping Pitney Bowes customers visualise and analyse their data using MapInfo Discover. Esther also enjoys ballet, being outdoors, and trying out new recipes.