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 2009
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 2009

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
ViaVirtualEarth
SVG Tutorials
MapPoint

Map Visitors

 Direct Media

Travel Insurance Compare over 450 travel insurance policies (inc. annual multi-trip, single trip & winter sports)

  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
-Help with Spatial Data/Table. Sql add-in Mappoint
-Matching by Zip Code
-Another Big Imagery Release for Bing Maps
-BingMapsDev: @csharpzealot and the 2.3GB download begins ;)
-BingMapsDev: Great new book in French on Bing Maps from @NicolasBoonaert http://bit.ly/ba72nc
-bingmaps: MapDotNet's entry to Azure US State and Local Government Application Development Contest with Bing Maps: http://miami311.cloudapp.net/
-Ability to change color of state lines?
-bingmaps: @chrispendleton on stage right now at TechDays in Paris. Presenting #BingMaps
-route directions????
-bingmaps: Interested in the rare trees of London? View them in this #BingMaps collection http://bit.ly/chOLp9
-MapPoint in Desktop Applications
-Varying travelling time by "time of day"
-Link using parameter query in Access, still no?
-Can I see a list of all pushpins?
-Assigning pushpins as territories
-Displaying info in the directions for a route
-Drive time polygons - help needed
-2002 Loading Help
-bingmaps: Webcast 10th Feb: #BingMaps ? Getting Started for Developers. Presented by @johanneskebeck http://bit.ly/8XhzCC
-bingmaps: Vancouver applications feature #BingMaps, just in time for the winter Olympics http://bit.ly/b0FoRj
-Vancouver Applications Feature Bing Maps
-Distance between locations
-bingmaps: Arlington, Virginia is using Bing Maps to help drive economic development. Check it out: http://bit.ly/1JCqpi
-bingmaps: Check out this cool video of US Navy (ONR) using Bing Maps for mobile command & control: http://bit.ly/3Jo2MX
-bingmaps: US Navy testing mobile command & control solution using Bing Maps & Windows Mobile phones. Case study: http://bit.ly/XEuF9
 Resources
Browse GIS books and periodicals
Best Car Contract Hire Lease Save
Find a MapPoint Partner or Consultant
Real Estate Columbia, MO Real Estate


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.

• Replacement Cordless Phone Batteries from DSMiller
Improve your career with a computer degree LocalEDU.com
• Tim Cohn's Marketing Strategy Consultancy
• Buy Toner Cartridges at Marquee Office Solutions
• Looking for Dry Erase Boards? See Dry Erase Boards • The Search Starts Here Used Cars
• 5339 - We Know Bikes: Road Bikes / Triathlon Bikes / Mountain Bikes / BMX Bikes
• Buy Your Car Used Cars UK, Car Lease and Contract Hire