Buy Now 

Free Trial

$695 (Or $395 Upgrade)



Maptitude Mapping Software

Programming Maptitude in Python 2 and Python 3

The Caliper Python module lets you access not only Maptitude, but also the .NET framework via any program written in Python 2.7 or 3.x. The Caliper Maptitude module works well with scientific Python distributions such as Anaconda Python.

Maptitude ships with two different Python modules. If you program in Python 2.7, import caliper. If you program in Python 3.x, import caliper3.

With the Caliper module, you can write a Python program like this one (in Python 3):

import sys, traceback, caliper3
dk = caliper3.Gisdk("Maptitude")
tutorial_folder = dk.Macro("G30 Tutorial Folder")
table_name = dk.OpenTable("airports","ffb",[ tutorial_folder + 
num_rows = dk.GetRecordCount(table_name,None)
options = { 'Index Limit': 0}
query = "select * where Domestic > 10000"
num_found = dk.SelectByQuery("high traffic","several",query,options)

with the Caliper Python module, you can:

  • Execute any GISDK function or macro via dk.FunctionName() and dk.Macro()
  • Call GISDK classes for geocoding (Data.Finder) and multi-stop routing and reporting (Routing.Router)
  • Access any .NET assembly via dk.CreateManagedObject()
  • Access any COM object via dk.CreateCOMObject()

Note that "Gisdk" with just the "G" capitalized is always used in Python programs.

Using the Caliper Module

Once the module is installed, you are ready to use it in a Python script or in the Python command line. The folder GISDK\Samples\Python contains an example Python script that you can use to get started.

In the Python command line, start by importing the modules sys, traceback and caliper and by creating a GISDK object, which holds a live connection to one Maptitude child process:

>>> import sys, traceback, caliper

>>> dk = caliper3.Gisdk("Maptitude")

>>> print dk

<Gisdk Maptitude>

The GISDK object can be created with three options:

  • application_name: the name of the Caliper product COM object, defaults to "Maptitude"
  • log_file: stores all run-time exceptions and errors raised by the COM object, defaults to "python.log"
  • search_path: custom search path to use when Maptitude opens files, defaults to None

>>> dk = caliper3.Gisdk(application_name="Maptitude",

         log_file = "python.log",

         search_path = None)

Now you are ready to use GISDK. You can call functions using the dot notation with the dk object:

>>> folder = dk.apply("G30 Tutorial Folder","gis_ui")

>>> table_name = dk.OpenTable("airports","ffb",[folder + "airports.bin",None])

>>> num_rows   = dk.GetRecordCount(table_name,None)

>>> print "table " + table_name + " has " + str(num_rows) + " rows."

table airports has 280 rows.

All of the GISDK functions are available as methods of the Python object dk. The general syntax is:

>>> result = dk.FunctionName(*args)

You can also call macros compiled into a GISDK module with the rscc tool. For example, to execute the macro called "Echo" located in the GISDK  module "gis_ui" you write:

>>> print dk.apply("Echo","gis_ui","string argument",123,{ "key": "value1" , "key2": "value2" })

["Echo","args[1]","string argument","args[2]",123,"args[3]",[["key2","value2"],["key","value1"]]]

The Python syntax to call a GISDK macro is:

>>> result = dk.apply(macro_name,path_to_compiled_ui,*args,**kwargs)


  • macro_name: name of a GISDK macro
  • path_to_compiled_ui: GISDK compiled "ui" file that contains that macro.
  • args: list of parameters to pass to the GISDK macro
  • kwargs: collection of named parameters for the GISDK macro

You can pass Python-style named arguments (*kwargs) to the GISDK macro, and they will be translated into an GISDK option array. For example, the Python call:

>>> result = dk.apply("Geocode Macro","c:\\data\\my_macros.dbd",address="1172 Beacon St",zip_code="02461")

will execute the macro called "Geocode Macro" compiled in the file "c:\\data\\my_macros.dbd", passing as named input arguments address and zip_code.

The "Geocode Macro" source code (e.g. my_macros.rsc) should look like this:

macro "Geocode Macro" (kwargs)

    input_address = kwargs.address

    input_zip_code = kwargs.zip_code

    // body of the macro here


Note that Python uses the keyword None instead of null. You can't leave it out as in GISDK; instead you have to write None for a null argument.

Note also that arrays and collections are two different objects in Python. Python uses square brackets for arrays:

[folder + "airports.bin",None]

Curly brackets are only used for collections, such as option arrays:

{ "key": "value1" , "key2": "value2" }

When you are done with Maptitude and you want to terminate the MAPT.exe child process, you can call the dk.Close() method:

>>> dk.Close()

Keep in mind that only one Python script can access Maptitude at the time, and that all GISDK method calls must be executed sequentially.

Programming Examples:

Here is an example showing you how to select data from a Maptitude table:

folder = dk.apply("G30 Tutorial Folder","gis_ui")
table_name = dk.OpenTable("airports","ffb",[folder + "airports.bin",None])
num_rows = dk.GetRecordCount(table_name,None)
print "table " + table_name + " has " + str(num_rows) + " rows."

options = { 'Index Limit': 0}
query   = "select * where Domestic > 10000"
num_found = dk.SelectByQuery("high traffic","several",query,options)
if ( num_found > 0 ) :
    print str(num_found) + " records match the query: " + query
    view_set = table_name + "|high traffic"
    field_names , field_specs = dk.GetFields(table_name,"All")
    print "field_names: " + str(field_names)
    print "field specs: " + str(field_specs)
    sort_order  = None
    options     = None
    order       = "Row"
    i = 1

for row in dk.GetRecordsValues(view_set,
    print "[row " + str(i) + "] " + str(row)
    i = i + 1 

This prints out the following to the console:

[row 1] (u'PPG', u'PAGO PAGO INTL', u'PAGO PAGO', u'AMERICAN SAMOA', u'AS', u'US', u'51525.*A', None, None, 0, 57835, 57835, u'Western-Pacific', u'HNL', u'Estimated', 30, u'GNC 20', u'Yes', u'CS 05/23', u'NGY', u'Yes')


 [row 2] (u'LNY', u'LANAI', u'LANAI CITY', u'MAUI', u'HI', u'US', u'52402.*A', None, None, 0, 84150, 84150, u'Western-Pacific', u'HNL', u'Estimated', 1308, u'HAWAIIAN ISLANDS', None, u'BS 05/73', u'NGY', u'No')

GISDK Classes and Objects

You can access in Python custom GISDK classes and objects. For example, you can write a GISDK   program with a class called "Calculator":

// Gisdk source code

// test this Gisdk class from Python

Class "calculator" (message,args))

    init do

        self.message = message

        self.args = args


    macro "add" (a,b) do



    macro "subtract" (a,b) do



    macro "macro with named args" (kwargs) do

        Return("address:" + kwargs.address + "zip code:" + kwargs.zip_code)



Use the GISDK toolbox to compile this code into a GISDK "ui" module, e.g. test.dbd. In Python, you can create an instance of the "Calculator" class by creating an object of type GisdkObject:

my_options = { "key": "value1" , "key2": "value2" }

c = dk.CreateObject("calculator","c:\\path\\test.dbd",my_options)

c.message = "this message is from python"

c.args = [ 2 , 3 , 4]

print c.message

print c.args

print c.apply("add",3,4)

print c.apply("subtract",4,5)

You create an instance of a GISDK class via the CreateObject() call:

Gisdk_object = dk.CreateObject("class_name","module_name",*args,**kwargs)

You access GISDK object properties using the dot notation (e.g. c.message), and you execute object methods via the apply method: e.g.:

Gisdk_object.apply('macro name",*args,**kwargs)


The Caliper module also supports working with vectors. You can create vectors using the whole set of GISDK functions, combined with the Python range shortcuts:

import sys, traceback, caliper

dk = caliper3.Gisdk("Maptitude")

folder = dk.apply("G30 Tutorial Folder","gis_ui")

view_name = dk.OpenTable("airports","ffb",[folder + "airports.bin",None])

v = dk.GetDataVector(view_name+"|","Name",None)

x = dk.VectorToArray(v)

print v

print x


x = dk.ArrayToVector([ 1 , 2, 3 , 4])

print dk.ShowArray([ "x" , x ])

v = dk.ArrayToVector(range(1,10,1))

print dk.ShowArray([ "v" , v ])

w = dk.ArrayToVector(range(101,110,1))

print dk.ShowArray([ "w" , w ])

z = dk.ArrayToVector([0]*10)

print dk.ShowArray([ "z" , z ])

You can use the GISDK assignment operator in Python "|=" also to work with simple arithmetic operations on vectors:

z |= v + w

print dk.ShowArray({ "v": v , "w": w, "z": z})

This prints to the console:

[["z",["vector",[0,0,0,0,0,0,0,0,0,0]]],["w",["vector",[101,102,103,104,105,106, 107,108,109]]],["v",["vector",[1,2,3,4,5,6,7,8,9]]]]

Accessing .NET Assemblies in Python

The Caliper GISDK provides a simple method called CreateManagedObject that lets you access any .NET assembly installed on your computer. Here is a simple example for the .NET class System.DateTime:

date = dk.CreateManagedObject(None,"System.DateTime",[1980,1,1,0,0,0,0])
is_gisdk_object = dk.IsGisdkObject(date)
if is_gisdk_object:
     net_class_info = dk.GetClassInfo(date)
     print("" + str(type(net_class_info)) + " " + str(net_class_info)) later_date = date.AddDays(300.00)
     print("First date: " + date.ToString())
     print("Later date: " + later_date.ToString())

Accessing COM Objects in Python

Any COM object is also accessible in the GISDK, via the call to CreateCOMObject(), like this:

xmldoc = dk.CreateComObject("MSXML2.DOMDocument.6.0") 
xmldoc.async = 0
xmldoc.validateOnParse = 0

More Information About Programming Maptitude in Python

If you would like more information about programming Maptitude in Python, including the Geocoding API and the Routing and Directions API, please contact Caliper Sales and we will be happy to provide you with example source code and the API documentation.