Follow us on Twitter

Calling ImportData & DisplayDataMap from Python

Share:

This article follows on from my recent articles about using MapPoint’s ImportData and DisplayDataMap methods. It demonstrates how to use these methods from a non-Microsoft language that only supports COM as an extension and not an integral part of the language and libraries.

I will assume that you are familiar with the basics of calling MapPoint from Python using win32com. The samples in this article use MapPoint 2010 North America, Python 2.7, and the IDLE Python IDE. The samples use the same modified sample data used in the previous ImportData article.

 

Some Initial Notes

win32com is actually pretty smart behind the scenes, making it very simple to pass relatively complex data structures such as two dimensional arrays. Simply pass a two dimensional Python list, and win32com will automatically convert it into the COM equivalent.

An inconvenience is the lack of enumeration constants. It should be possible to write a script that creates a Python module to list these. However, I chose to simply inline the numeric values with suitable comments. Luckily, the MapPoint documentation lists all of the MapPoint enumeration values.

A potentially bigger problem concerns ‘missing’ optional parameters. .NET provides the System.Reflection.Missing.Value constant that can be passed to indicate a ‘missing’ optional parameter.  In theory, win32com will do the same when it sees the None constant. Unfortunately, this does not always work. For some parameters, MapPoint/COM will throw an exception, and you are forced to manually insert the required default value or array.

 

Using ImportData

Here is the C# ImportData example converted to Python with explicit field specifications:

It is still possible to default the field specifications by passing None instead of the fieldSpecifications array:

 

DisplayDataMap

As with the C# examples, DisplayDataMap is a little more complex.

Here is an example that draws shaded same-sized circles with an array of custom ranges:

This is works very well, but the last four parameters (ArrayofCustomNames, DivideByField, ArrayOfDataFieldLabels, and ArrayOfPushpinSymbols) cannot be defaulted using the None constant. They can either be simply left off the parameter list (as above), or they have to be explicitly listed with valid arrays. For example:

 

Conclusions

ImportData and DisplayDataMap are more complex than most MapPoint methods, but both can be successfully called from Python. Object array parameters can be easily passed as standard Python 2d lists. However, enumeration constants are not automatically defined, and some optional parameters have to be explicitly provided.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">