spacer1
spacer2 1_1 1_2
2_1
 Subscribe
 The MP2K Update!
 
 
 
 Magazine
Front Cover
What's New
Articles
News
Sample Data
Gallery
Advertise
About
 Features
MapPoint 2011
Press Releases
MapPoint Forums
Companies
Link to MP2Kmag
Wish List
MapPoint Trial
Authors
 Earlier Content
Past News Items
Past What's New Announcements
 Sponsors
 Order

MapPoint 2011

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
SVG Tutorials
MapPoint

Map Visitors

  ARTICLES  


Using Python to Control MapPoint, Part 1

First of two articles by Richard Marsden on scripting MapPoint using Python. This article demonstrates how to get started with PythonWin and MapPoint.

Python is an easy to use but powerful scripting language. Python is ideal for processing data and text. This sounds a bit like Perl, but unlike Perl, I find Python much easier to read and maintain. A wide range of available extensions make Python an ideal tool for scripting MapPoint. Part 1 of this series shows you the basics of controlling MapPoint with Python. Part 2 will use some basic Python text processing to read a file of summary US Census data and plot the filtered results in MapPoint.

These examples use Python 2.4. This can be downloaded from http://www.python.org. I have installed it into the installer’s suggested directory of c:\Python24. If you use a different directory, you will need to modify the following instructions accordingly.

To access COM, I used the Python Windows Extensions (“PythonWin”). These extensions also include a simple IDE (Interactive Development Environment), and some Windows GUI extensions. The PythonWin installer can be downloaded from http://www.python.org/windows/pythonwin. Ensure that you download the version that matches your version of Python. Install PythonWin after Python.

In order to access MapPoint’s objects and methods, you need to convert MapPoint’s COM Type Information into a form that Python can read. This is performed using the PythonWin make-py Python script. From the command line, this is performed as follows:

C:\> cd “\Program Files\Microsoft MapPoint 2004”
C:\> \Python24\Lib\site-packages\win32com\client\make-py.py mpna82.tlb > \Python24\mpna82.py

This example is for MapPoint 2004 North America. You will need to change the name of the directory and MapPoint’s tlb file if you are working with a different version.

The Type Information will now be contained in mpna82.py in the main Python directory.

Start Python. Type the following code in at the command prompt, or enter it into a text file and run it as a program:

# Import the PythonWin win32com components that we require
from win32com.client import constants, Dispatch

# Useful shorthand: Change the object name for Europe, 
# MapPoint 2002,etc.
MAPPOINT = ‘MapPoint.Application.NA.11’

# Create the MapPoint Application object
myApp = Dispatch(MAPPOINT)

# We can easily call MapPoint methods like this:
myApp.NewMap

# Setting and getting MapPoint properties is just as simple:
myApp.Visible = 1
myMap = myApp.ActiveMap

# Let’s do something interesting…
# Create a Location object, and then use it to create a new pushpin
myLoc = myMap.GetLocation(32.0, -96.0)
myMap.AddPushpin( myLoc, “A pin near Corsicana, Texas”)

In Part 2, I shall use Python to process some summary US Census statistics, and use MapPoint to plot cities that match certain characteristics.

Further Reading

“Learning Python”, Mark Lutz & David Ascher, Publ. O’Reilly.

Discuss this story in the forum.

Author: Richard Marsden
Email: enquiries(AT)winwaed.com
URL: http://www.winwaed.com
Richard Marsden is the proprietor of Winwaed Software Technology, LLC which provides software consulting and development services, specializing in both MapPoint and online mapping applications. He operates the Mapping-Tools.com Website for MapPoint Tools and Utilities, and recently launched the GeoWeb Guru a community website for developers of the geospatial web. In 2008, Richard was awarded Virtual Earth MVP status by Microsoft.

Prior to Winwaed, Richard worked as a software developer working on seismic processing algorithms for the oil exploration industry. He holds geology and geophysics degrees from the University of Cambridge (Churchill College), and the University of Durham; and an interdisciplinary MBA from the University of Dallas.



Google
 
MP2Kmag Internet


 Recent Discussion
-MP 2011 Silent Install with Key AND Activation?
-Convert .GmL to a spatial data type
-bingmaps: Spouse run interference on an Indianapolis road trip for Super Bowl? Get the best view on Bing Maps. BYO beer & chips*http://t.co/hkZlFnJ4
-MAP POINT Route Planning
-MapPoint Routes: Multiple start points, one stop point.
-Export Territories - plot them on google maps or bing
-bingmaps: Check out this blog and interview to learn more about LifeLens and Bing Maps http://t.co/mlNHyKdW
-Can't make working OLAP add-in
-Importing data from Canada?
-MapPoint North America 2011 - UK Postcodes?
-Seeking Church Demographic info for MP2011
-Exporting Pushpin Counts in a radius
-bingmaps: RT @bing: Congrats to the Imagine Cup Grant Winners, esp. OaSys and LifeLens using @Bing maps! http://t.co/Fha9Cf0V
-Store Distance Calculations
-Modify maps
-Win7x64SP1 clobbers MapPoint 2010....
-bingmaps: RT @ChrisPendleton: New Bing Maps Features Help You Feel Spatial…
-Hope it doenst soudn TOO much like Im a Noob.. BUT...
-Capture click events from MapPoint to my Winforms app?
-bingmaps: @natelawrence Thanks for the feedback...check out our*Forum for technical assistance:*http://t.co/WDAjNJCD
-bingmaps: @Jordanaous*We're glad you're enjoying Streetside...thanks for using Bing Maps!
-bingmaps: @Goodlett*A beautiful partnership, indeed.
-bingmaps: @urbanmapping Love the fascinating questions you guys are asking, and the important information you provide. Keep it up!
-bingmaps: @beeinthehive*Happy to help! Thanks for using Bing Maps!
-bingmaps: @Geocrusader80* Isn't the imagery amazing? Glad you're a fan!
 Resources
Browse GIS books and periodicals
Find a MapPoint Partner or Consultant
Real Estate Columbia MO Homes for Sale


Want Your Site To Appear Here?

   © 1999-2009 MP2K. Questions and comments to: website@mp2kmag.com
  Microsoft and MapPoint 2002/2004/2006/2009 are either trademarks or registered trademarks of Microsoft.



• Buy Your Car Used Cars UK, Car Lease and Contract Hire