Jump to content

Custom Script to Apply Shortnames and combine GPX data


Recommended Posts

Original post can be found here: http://forums.Groundspeak.com/GC/index.php?showtopic=319986

 

I am posting here with a better Topic Title in case any others would find themselves using this I can compile to a .exe and maybe take the time to do a GUI Frontend for a stand alone windows application.

 

Start of original post:

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

I may be close to a conflict of interest on this one, but as a moderator, I see no reason to discourage someone from sharing a (free) tool they've created to make geocaching easier for others. If I hadn't been unhappy with gpsutil and created GPSBabel and given it away, I'll be so cocky as to say that the state of Geocaching apps would be very different.

 

Just because it's not useful to you or you're terrified of regularly expressions doesn't mean it's not useful to others. Please be respectful of posters that have created and are sharing something for others.

 

Let's not organize book burnings just because you're not interested in the book.

 

P.S. I think you can leave the ".exe" out and it'll work without changes on any of the OSes...

Link to comment

I don’t think I am guilty of what you imply. I did not discourage him from publishing it but after someone else pointed out that there are already programs that do it I supported that. That occurs almost daily on this forum. Most often mentioned is GSAK which I wasn’t the first to mention.

I don’t understand “not useful to you or you're terrified of regularly expressions “ did it get changed by auto correct or something.

I think all my comments were respectful but you seem to think that content you disagree with is not respectful.

It seems to me the book burning was in two statements.

“if memory serves correct gsak can be confusing and also to use some of the features you have to pay for them”

And

“GSAK I know for a fact will not run on Linux without a Virtual machine”

Both of these statements were burnings of GSAK which I responded to in a respectful manner pointing out facts and explaining that GSAK isn’t always that confusing.

Given that 125 people have viewed this topic and no one has raised his hand and said “Please send a copy to me when you have it done” seems to validate my sentiments. The great void of silence on the subject speaks for itself.

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