Developer Dojo: Getting started with the MapInfo Pro Raster API

MapInfo Pro™ Monthly Journal
Developer Dojo: Getting started with the MapInfo Pro Raster API
Raster Late last year Pitney Bowes released the first version of MapInfo Pro Advanced. MapInfo Pro Advanced is a new edition of MapInfo Pro that is licensed to run MapInfo Pro Raster, the new raster and grid engine that allows MapInfo Pro users to work with huge raster data sets.

MapInfo Pro Advanced includes a .NET based API that allows you to write custom applications or functions that take advantage of MapInfo Pro Raster to automate certain tasks or add new functionality that may not be easily achieved by just using the application interface.
In this article, I will show you how to get started with the MapInfo Pro Raster API and write some simple extensions for MapInfo Pro Advanced using MapBasic and the new Raster API.

Getting started with the MapInfo Pro Raster API

In Visual Studio .NET (2013 or 2105, Express, Professional or Enterprise Editions) we first need to add a reference to some MapInfo Pro Raster assemblies.

Via the Reference Manager, you need to browse to the Raster installation folder in your MapInfo Pro installation folder and select the three highlighted dll's. 

Visual Studio Reference Manager

Now you can add the Using statements for these three assemblies so that you don not have to use the fully qualified path to the MapInfo Pro Raster methods when you are using them.

Adding Using Statements

Writing applications using the MapInfo Pro Raster API

Now we are ready to start writing some methods using the MapInfo Pro Raster API. In this very first basic example, we will write a method that takes a list of input raster files and we will Merge these into a single MRR output file.

In this example we hardcode many of the settings for the output file, but we could also have added these as parameters to the method or derived them after analysing the input and output raster file formats.

This is our final method for merging input raster files into a single MRR raster file. 

MergeAsMRR Method

Now we can either build this solution as an EXE or DLL assembly. We will build as a DLL so that we can call the MergeAsMRR function from our MapBasic application.

Writing the MapBasic application

In this example, we will take advantage of some modules in my mbLibrary that can be found here on Github: mbLibrary.

It is essentially the FILELib module and the associated FILELib.dll that I am using. By default, my applications are designed to use a wider variety of the modules in that library.

Below you can see the list of includes that my application is using. I have highlighted the FILELib module that I am going to use specifically for this project. 

List of Includes

First, we need to declare the .NET method MergeAsMRR so that MapBasic knows how to access it. I have highlighted that specific class declaration below.

Notice that I give it a different name to use in MapBasic than the name it has been given in the .NET source code/assembly. I also need to specify the class and the assembly name that this method can be found in. 

Declare Method MergeAsMRR

Now, I am ready to use this method from my MapBasic application.

I will ask the user to select a folder and enter the name of the output MRR file they wish to create.

I will then search the folder for a specific raster filetype. In this case, I am searching for files with the extension .TIF (GeoTIFF) but I could also have chosen other format extensions such as .ASC (ESRI ASCII Grid).

Finally, I am calling the .NET method to Merge the found files into a single MRR file. 

Sub MENUMergeFilesInFolder

And that's all there is to creating a simple extension for MapInfo Pro Advanced using the new MapInfo Pro Raster API. Happy coding! 

About the Author
Peter Horsbøll Møller is currently working in the EMEA Channel Enablement team at Pitney Bowes focusing on the GIS & LI products. Peter has two decades of experience within the GIS space having helped organisations in a number of countries to take advantage of the MapInfo portfolio. To find out more, visit his LinkedIn profile here. When not working Peter is an aficionado of fine whiskey and good cigars.
UPDATED:  July 1, 2017