Create Custom GPX to Features Tool for Garmin Data Collection

26 Jan 2013 Update: The developer who maintains this tool discovered this post last week, got in touch and asked for a sample GPX file. He implemented a fix to recognize the <cmt> tag. Look for the <cmt> tag to be automatically imported by the GPX to Features tool in an upcoming release of the software.

Esri included a script tool as part of ArcGIS 10.1 for importing files directly from GPS receivers, the GPX to Feature Class tool. However, for it to work as expected with Garmin GPS receivers, the tool needs to be copied and modified just slightly.

Garmin eTrex 10 - Notice the Note field

I recently purchased a Garmin eTrex 10 for collecting data while out mountain biking, paddling and hiking. When entering  waypoints using the eTrex, I tried taking advantage of the note field to enter supplementary information.

After collecting a few points out in the parking lot with my eTrex, I used the GPX to Features tool to bring the points in as a feature class. The points appeared just as expected in ArcMap. Opening the attribute table was somewhat disappointing. For each of the waypoints I had entered some notes. These notes were nowhere to be seen in the attribute table. There is a field called Descript, but nothing was populated for any of the features.

Since the GPX to Features tool is included as a script tool, it can easily be copied and modified. After creating a custom toolbox, I copied and began to examine the script. There is an inconsistency between what the Python script was expects and the xml structure the eTrex creates.

The Garmin is saving the notes in a tag named <cmt>, but the GPX to Features tool is expecting a tag called <desc>. Changing desc to cmt in two places on line 159 of the GPX to Features tool will ensure notes entered in the eTrex will be populated into the Descript field created by the GPX to Features tool.

If you want the easy solution, I have included this modified script tool in a toolbox in this GPS Toolbox. The toolbox is contained inside the zipped archive. However, if you are interested in how the solution was created, or simply want to do it yourself, read on.

To remap the cmt tag into the Descript field, you will need to:

  • create a custom toolbox
  • copy GPX to Features into your custom toolbox
  • save the script file to a new location
  • edit the properties of your custom tool to reference the saved script file
  • edit the script
  • optional: import the script
The first step is to create a custom toolbox. This can be saved anywhere. I chose to save it in the default ArcGIS directory, but you can save it in any folder. To create this toolbox, simply right click on the folder in the Catalog window and select New > Toolbox. With your custom toolbox created, next copy and paste the GPX to Features tool (Conversion Tools > From GPX) into your new custom toolbox.

Although you copied the tool into your custom toolbox, it is still referencing the original Python script. To edit the script you will first need to save a copy and tell your custom tool to reference this new copied script. The original script can be accessed by right clicking on your newly copied GPX to Features tool and selecting Edit from the context menu. This will open the original script located at C:Program FilesArcGISDesktop10.1ArcToolboxScriptsGPXtoFeatures.py. From the file menu, select Save As. Save the script using a new name such as GPXtoFeaturesGarmin.py someplace you will remember. I simply saved it in the default ArcGIS folder, the same place where my custom toolbox is located.

With the new script saved, your tool properties need to be modified to reference this new script. Access these properties by right clicking on the tool in your custom toolbox. Select Properties from the context menu. Under the second tab in your tool properties, called Source, browse to and select the script you saved, likely called GPXtoFeaturesGarmin.py if you followed my suggestion earlier.

While in the properties dialog, you may as well change the name of the script so it can be differentiated. Switch back to the first tab, General, and if following my lead, change Name to GPStoFeaturesGarmin and the Label to GPX to Features (Garmin).

With the tool referencing an editable copy of the script, you can now edit the copied script. Just like before, right click on the tool in the custom toolbox (likely called GPX to Features (Garmin)) and select Edit from the context menu.

Now, in the code editor, locate line 158 inside the _getNameDesc function. It reads...

desc = node.find(TOPOGRAFIX_NS + 'desc').text or '' if node.find(TOPOGRAFIX_NS + 'desc') is not None else ''

Change the two instances of desc to cmt so it looks like this...

desc = node.find(TOPOGRAFIX_NS + 'cmt').text or '' if node.find(TOPOGRAFIX_NS + 'cmt') is not None else ''

Save and close the script. Now when importing GPX files created with Garmin GPS receivers, anything entered in the Notes while collecting waypoints will be populated into a Descript field as text when using your customized GPX to Features (Garmin) tool.

Optionally, if you want to make the toolbox slightly more portable, import the script into the tool. Right now you will need to make sure if you copy or move the toolbox, it does not get separated from the Python script file (py file). However, once you import the script, you no longer have to worry about this.

To import the script into the tool, right click and select Import from the context menu. The script is imported. To move, copy and share this tool, all you have to do is share the tbx file, your custom toolbox. Now you have a completely portable script tool for ArcGIS Desktop for importing GPX files from a Garmin GPS receiver.

Reference: Download GPS Toolbox