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

MapPoint 2006

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
ViaVirtualEarth
SVG Tutorials
MapPoint

Map Visitors

 Direct Media

IT support
Connect.co.uk provides top-notch IT Support for small and medium-sized enterprises.

ink uk
Thinking ink? We are UK ink specialists, supplying home business and trade users. When getting ink, get in touch. Ink excellence.

Cheap flights to Madrid
Visit Madrid with bullfighting and the "Golden Triangle of Art" ready for you to view. For cheap flights to Madrid book here.

Tenerife Holidays
Tenerife is one of the last remaining European paradise islands. You can book great cheap holidays at On The Beach.

apartments Bulgaria
Apartments available for sale in ski resorts in an around Bulgaria. Choice of custom build or ready made!

Cheap Flights Miami
The best way to find cheap flights to Miami and many other destinations is to shop around. Use dealchecker.co.uk to compare prices.

Paphos
Vacation to Paphos? This year round destination offers a lively but relaxing holiday. Check out the fabulous deals on Ulookubook.com.

  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, specialising in geographic, graphical, and scientific applications. He is currently able to offer mapping solutions using MapPoint and/or the Gistix Toolkit; and operates the Mapping-Tools.Com Website for MapPoint Tools and Utilities.

Previous to Winwaed, Richard has worked as a software developer in the seismic exploration business.

Richard holds geology and geophysics degrees from the University of Cambridge (Churchill College), and the University of Durham.



Google
 
MP2Kmag Internet


 Recent Discussion
-Information about area
-Territory information
-Gps task pane in ActiveX
-Worldwide Telescope Now Available!
-c++ - setting the color of a line
-Initial Costa Rica MapServer map is up & running!
-Satellite Images of Myanmar Cyclone Damage
-Virtual Earth Loyalist: Aerial View
-Leaving messages on the Virtual Earth for Government blog site
-Virtual Earth Webcast: Adding Mapping Capabilities to your Applications with Virtual Earth
-Get new Lat & Lon from speed
-Integrating Virtual Earth Maps and Excel 2007
-Zillow.com
-ADODB Recordset to MapPoint.DataSet
-Why my new phone isn't an iPhone
-Version 6.0 to 6.1 Auto-Upgrade Alert & V 3-5 Deprecation Reminder
-Accessing MultiMap in the UK. Plus a comparison of UK mapping sites.
-Duplicate double-clicking State name in code?
-Multi-multi-core AMD chips
-Graticule Grids in Virtual Earth
-Location & FindResults not always returning City/State/etc.?
-findout centre of location from a set of long and lat
-How to terminate the process of async webservice method
-Business & trendy mobile phones
-Microsoft Spatial
 Resources
Browse GIS books and periodicals
Best Car Contract Hire Lease Save
Find a MapPoint Partner or Consultant
Real Estate Columbia Homes for Sale by Owner


Want Your Site To Appear Here?

   © 1999-2008 MP2K. Questions and comments to: website@mp2kmag.com
  Microsoft and MapPoint 2002/2004/2006 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, Ink Cartridges & Drums at Marquee Office Solutions
• Looking for Dry Erase Boards? See Dry Erase Boards
• 5339 - We Know Bikes: Road Bikes / Triathlon Bikes / Mountain Bikes / BMX Bikes
• Buy Your Car Used Cars, Car Lease and Contract Hire