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

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
SVG Tutorials
MapPoint

Map Visitors

  ARTICLES  


Waypoint Importer For MapPoint

In this article, Rahn Lieberman shows how to import an XML file containing waypoint information into MapPoint 2002 as Pushpins

Introduction

Geocaching is a high-tech treasure hunt. You’re given the longitude and latitude of a cache, and try to find it using a GPS unit. One Web site for the sport is at www.geocaching.com, where a listing of geocaches is available, along with additional information.

The process of entering the coordinates of a cache into your GPS can be fairly tedious. EasyGPS (www.easygps.com) has developed a means of downloading a list of caches. Using the EasyGPS software, you can easily sort and transfer waypoints and geocaches to your GPS.

A shortcoming of the EasyGPS software is that it does not provide any mapping capability to use with the waypoints. With this COM Add-In, you can import all of the waypoints in an EasyGPS file into MapPoint as Pushpins.

This article will discuss the file format of the EasyGPS .loc file, building a COM Add-In and GUI to point to the file, and using the MSXML 3.0 object to read the file.

Requirements

I developed the program in Visual Basic 6 (SP3) on Windows XP Professional. MapPoint 2002 is required.

The EasyGPS File

On www.Geocaching.com, you can download any geocache as an EasyGPS file. You do not need EasyGPS installed on your computer.

An EasyGPS file downloads with a .loc extension by default. Opening it up in your favorite text editor reveals that it is in fact XML. I’ll use the following sample file (and call it the loc file from here on out.):

By inspection, the breakdown of the file is as follows:    

  • Loc: The base node of the XML
  •    
  • Waypoint: Each waypoint is stored as a node in the XML file
  •    
  • Name: The name of the waypoint is given by this child node. The CDATA defines this as plain text. The waypoint ID (assigned by Geocaching.com) is given as an attribute
  •    
  • Coord: this is the coordinates of the waypoint in decimal degree format.
  •    
  • Type: This is the waypoint type. In this case, all waypoints are geocaches
  •    
  • Link: The URL to the geocache is given for easy linking
  • A simple explanation of this XML is that it is a tree structure. The loc node is the base node of the tree, and everything else is a child node of it. The waypoints are one level below this. Each of the other nodes (name, coord, etc.) is a child node of the waypoint.

    The MSXML object uses a zero-based system to refer to items within the XML tree. The first waypoint will be childnode(0). The second waypoint will be childnode(1). The attributes within each tag are also zero-based, so in the coord node, lat is attribute(0) and lon is attribute(1).

    Note: In the Name node, the CDATA at the beginning of the text tells the parser that the following information is plain text and should not be marked up. It is handled automatically by the XML parser. The Waypoint ID (an attribute of this node) is assigned by the www.geocaching.com database and can be used as a simple identifier on a GPS. (Most GPS units do not allow you to use elaborate naming of waypoints.)

    The COM Add-In

    The COM Add-In should read the loc file and place a Pushpin on a MapPoint 2002 map for each waypoint. The Add-In should have a user interface where the user can indicate the location of the loc file and make selections about formatting, such as whether to display the headings and how to display the coordinates. The heading for the Pushpin should have the cache name and ID number. The description should contain the actual coordinates.

    Creating a COM Add-In in Visual Basic has been explored in other articles. I used the information in Rich Born’s article "MapPoint Graticule COM Add-In" and from MSDN to develop this Add-In.

    To get started:    

  • Create a new Add-In project in Visual Basic
  •    
  • Open the Designers/Connnect and change the Name property to Waypoint Importer and the Application property to Microsoft MapPoint
  •    
  • Open the code of the Designer and replace all the code with the following:
  • You will need a few references in the project, so add the following from the Project/References menu:    

  • Microsoft MapPoint 9.0 Object Library (use the appropriate region, North America or Europe)
  •    
  • Microsoft XML, v3.0
  • I like to use the Common Dialog control to help manage anything to do with opening and saving files, so we’ll use it. From the Project/Components menu, add a reference to Microsoft Common Dialog.

    We are now ready to get to the good stuff! Open the default form, frmAddIn and add the following to it:

         
    • A textbox named txtPath to hold the path of the loc file.
    •    
    • A Browse button named cmdBrowse, to browse for a file if you don’t know the path.
    •    
    • An Import button named cmdImport, to start the import routine.
    •    
    • A Cancel button named cmdCancel, to escape the Add-In.
    •    
    • A common dialog control named CommonDialog1 to provide the browse functionality.
    •    
    • A frame for controlling Pushpin Properties. In this frame, add the following three option buttons:
      •        
      • optNone, with the caption set to “no caption”
      •        
      • optTitle, with the caption set to “Title Only”
      •        
      • optFull, with the caption set to “Full caption”
    • A frame for selection of coordinate display. In this frame, add the following two option buttons:
      •        
      • optCoordDecimal, with the caption set to “Decimal degrees”
      •        
      • optionDMM, with the caption set to “Degree decimal minutes,” which is the format most geocachers use
         
    • A checkbox named chkView to display a message box of information for every point imported.
    • Labels for the above controls as needed for usability.
    • For the option buttons, choose which one of each group should be the default, and set it’s value property to true

    Here is the complete code for the form. I’ll talk about the details below.

    There are a few general routines for housekeeping:    

  • CancelButton_Click hides the Add-In, effectively closing it    
  • cmdBrowse_Click brings up the common dialog open window when the browse button is clicked. A filter is set to show loc files (*.loc), XML files (*.xml) or all (*.*) files.    
  • txtPath_Change sets the common dialog filename property so it points to the correct file if the path is manually entered into the text box txtPath    
  • The function MakeDecDeg converts decimal degrees into degree decimal minutes.

    The sub cmdImport_Click is the workhorse of the program.

    The first lines are variable declarations. Notice we declare some XML document variables for the XML parser. We also declare some MapPoint variables.

    The following lines setup our XML document object and load the loc file. This is all that is required! No messing with input or get statements, which is one of the big bonuses of using the MSXML object.

    'initialize XML doc
    Set xDoc = New MSXML2.DOMDocument
    xDoc.Load (CommonDialog1.FileName)
    

    Next we connect to the current map using the following code. :

        'initialize MapPoint app
        Set mpApp = g_oApp 'New MapPoint.Application
        Set mpMap = mpApp.ActiveMap
        mpApp.Visible = True
        mpApp.UserControl = True
    
    Now, make sure the XML document contains some nodes by counting the number of children in the root node. If it is 0, then there is nothing in the file to look at. Note there are a few fancy error- trapping methods of the MSXML object that could be used to validate the XML.
    lRecordCount = xDoc.documentElement.childNodes.Length
    If lRecordCount > 0 Then
    

    Now the code loops through the XML document and grabs the next waypoint node. The following lines read each waypoint and assign the values to variables:

    Since we know the format of the node, we can point to the specific children nodes to grab the information we want and assign it to variables.

    For example, the name of the waypoint is in the “name” child node, which will always be the 1st child node of the waypoint. The waypoint ID is always an attribute of this node.

    The following code inserts a Pushpin into the MapPoint map and formats the heading:

    The Pushpin’s location is set by a call to GetLocation, using the latitude and longitude of the waypoint. The name of the waypoint is put into the Pushpin’s heading. The coordinates are added based on the user’s preferred style. It also puts in the link to the Web page.

    For easy visibility, set the Pushpin symbol to a big red dot (a built in type). An improvement to the program would be to let the user chose the Pushpin symbol.

    Lastly, the Pushpin balloon state is set based on the user’s preference and the map is moved to the Pushpin location.

    To complete the project, compile the DLL and open MapPoint. On the Tools menu, choose COM Add-Ins, click Add, and then click your new DLL. You should now have the Waypoint importer on your Add-In menu, ready for use.

    Discuss this story in the forum.

    Author: Rahn Lieberman
    Email: rahn(AT)theliebermans.com
    URL: http://www.theliebermans.com
    Rahn is a software tester in the Seattle, Washington area. His computer interests include databases, programming and GIS applications. When not sitting in front of the computer, he enjoys rock climbing, mountain biking and running, all which combine nicely with geocaching. He recently completed a lifetime goal of running a marathon, and is more than happy to tell anyone that pauses long enough to listen about it.



    Google
     
    MP2Kmag Internet


  •  Recent Discussion
    -GCPowerStation v17.2
    -GCPowerStation v17.2
    -Gaussian 09W v8.0 Rev B.01 SMP
    -Gaussian 09 E.01 Linux64
    -Atmel Studio v.7.0.1931
    -Steinberg Cubase Elements v9.5.40 WiN
    -Nero Platinum 2019 Suite 20.0.05900 Multilingual
    -Serif DrawPlus X8 14.0.0.19
    -PROMT Master 19 Final + PROMT 19 Dictionary Collection
    -Apple Logic Pro X v.10.4.2 Multilanguage (MacOSX)
    -PROMT Expert 19 Final + PROMT 19 Dictionary Collection
    -Waves Complete v2018.10.16 WiN by R2R
    -VMware Fusion Pro 10.1.1 MacOSX
    -Foxit Phantompdf Business v.9.3.0.10826 Multilanguage
    -Bluestacks v4.31.56.2510 Multilingual
    -Xara Web Designer Premium 16.0.0.55162 (x64) Portable
    -Adobe Bridge CC 6.1.1.10 Update 3 by m0nkrus
    -Garmin MapSource v5.4
    -Alien Skin Exposure X4 Bundle 4.0.2.43 | macOS
    -Unity Asset Cubebrush - Scrap City Assets 1.0 x64
    -Magix Samplitude Pro X3 Suite v.14.4.0.518 Multilanguage
    -Waves Complete v2018.10.16
    -Oxygen XML Editor 18.0 (Win/Mac/Lnx)
    -Steinberg Cubase Elements v9.5.40 WiN
    -The Foundry Nuke Studio 11.2v4 Win x64
     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-2012 MP2K. Questions and comments to: website@mp2kmag.com
      Microsoft and MapPoint 2002/2004/2006/2009/2010/2011/2013 are either trademarks or registered trademarks of Microsoft.