Jump to content

gpsbabel command line display cache name


teamalizelos

Recommended Posts

My goals:

 

Display cache name rather than geocache code on my garmin 2555LMT

 

I want to accomplish the above in Linux with gps babel. If anyone runs gpsbabel in Windows I am sure that this can be accomplished the same way. Currently I am running the following command below which will remove duplicates from two pocket queries. I pull from two zipcodes so there is some overlap. I do have icons show up for the caches as poi icons but it still shows geocache codes not cache names on gps.

 

gpsbabel -i gpx -f Denton.gpx -f FM.gpx -x duplicate,location,shortname -o garmin_gpi,bitmap="geocaching.bmp" -F Geocaching.gpi

Link to comment

actually I did find a solution for what I was wanting to do it is just a matter of editing the xml.

 

What I do is use babel to combine and remove two of my pocket queries into one removing duplicates then do a find and replace for urlname and name xml tags reiterating line by line just swapping them. then finally using babel again to output a final gpi with poi icon. Now the actual cache names show up on my garmin gps. So I don't need windows or gsk at least for what I am wanting to accomplish. Below is my c0de.

 

#!/usr/bin/python -tt

import re
import os

os.system("gpsbabel -i gpx -f Denton.gpx -f FM.gpx -x duplicate,location,shortname -o gpx -F 1.gpx")

name = re.compile("\s\s<name>.*<\/name>")
urlname = re.compile("\s\s<urlname.*<\/urlname>")

filehandler1 = open('1.gpx', 'r')
filehandler2 = open('final.gpx', 'w')

for line in filehandler1:
 if name.match(line):
   newline = line.replace('<name>', '<urlname>')
   finalline = newline.replace('</name>', '</urlname>')
   filehandler2.write(finalline)
 elif urlname.match(line):
   newline = line.replace('<urlname>', '<name>')
   finalline = newline.replace('</urlname>', '</name>')
   filehandler2.write(finalline)
 else:
   filehandler2.write(line)    
filehandler1.close()
filehandler2.close()

os.system("gpsbabel -i gpx -f final.gpx -o garmin_gpi,category=Geocaching,bitmap=geocaching.bmp -F Geocaching.gpi")

os.remove("final.gpx")
os.remove("1.gpx")

print "Done"

Edited by teamalizelos
Link to comment

Will try to use the -s switch all this c0ding and you already had a solution I will see what I can come up with.

 

Do you know of geocaching.com api support being able to download your pocket queries automatically??

 

ideally i would like to plug up my gps run one script from my nix box and viola I am updated.

Link to comment

Wasn't able to get babel to do what I wanted. I will just rock my python script for now since it seems to work.

 

Thanks for your insight!!

 

if you have a working command line example to get gpsbabel to do smart names that would be cool.

 

gpsbabel -V

 

GPSBabel Version 1.4.3

 

edit:

 

I have tried several iternations of the -s switch without any luck

Edited by teamalizelos
Link to comment

I know my post here is old just got back into geocaching more and revived my old code to work with gpsbabel under windows. To have the code work under linux just remove the .exe from the os.system calls.

 

The reason for creating the code is to have multiple pocket queries on my Driving Garmin NUVI with POI icon data and the short name showing up rather than the cache name as GCXXXXX etc.

 

To use:

 

1. Download all your pocket queries to one folder

2. Extract the zip files in that same folder

3. Change line C:\\Users\\' + currentuser + '\\Desktop\\geocaching if needed (If you store the pocket queries in a folder on your desktop named geocaching and using windows you likely can skip this step)

4. Have a bmp file in the same directory you are running the script from that is no larger than 24x24 pixels

5. Run the script

6. Copy the remaining Geocaching.gpi to Garmin in path of Garmin\Poi (I had to create the folder Poi in Garmin folder)

 

If enough people would be at all interested in using this script I may put forth the effort to create a GUI Frontend to where you can click browse to go to the folder that your gpx data is located and also a browse feature for the bmp icon and allow this to be optional. Thanks a ton for the hard work to the developer(s) of gpsbabel which acted as a swiss army knife in accomplishing what I was wanting to do with the script. Maybe there is a command line switch already but in the past I was unable to get this working to display the cache names on my Garmin NUVI hence why I decided to code a script in the first place. I believe the previous version of gpsbabel I was using this feature was not working properly so I coded around it.

 

import re
import os
import fnmatch
import getpass

currentuser = getpass.getuser()

matches = []

for root, dirnames, filenames in os.walk('C:\\Users\\' + currentuser + '\\Desktop\\geocaching'):
 for filename in fnmatch.filter(filenames, '*.gpx'):
   if not re.match('.*-wpts.gpx', filename):
     matches.append(os.path.join(root, filename))

mystring = ""

for match in range(len(matches)):
 mystring+=str(" -f \"" + matches[match] + "\"")

finalstring = mystring.replace('\\', '/')

os.system("gpsbabel.exe -i gpx" + finalstring + " -x duplicate,location,shortname -o gpx -F 1.gpx")

name = re.compile("^\s+<name>.*<\/name>")
urlname = re.compile("^\s+<urlname.*<\/urlname>")

filehandler1 = open('1.gpx', 'r')
filehandler2 = open('final.gpx', 'w')

for line in filehandler1:
 if name.match(line):
   newline = line.replace('<name>', '<urlname>')
   finalline = newline.replace('</name>', '</urlname>')
   filehandler2.write(finalline)
 elif urlname.match(line):
   newline = line.replace('<urlname>', '<name>')
   finalline = newline.replace('</urlname>', '</name>')
   filehandler2.write(finalline)
 else:
   filehandler2.write(line)    
filehandler1.close()
filehandler2.close()

os.system("gpsbabel.exe -i gpx -f final.gpx -o garmin_gpi,category=Geocaching,bitmap=geocaching.bmp -F Geocaching.gpi")

os.remove("1.gpx")
os.remove("final.gpx")

print "Done"

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...