Look up cache information with gpsbabel
I tend search out my geocaches when I get a chance and keep them in a huge GPX file. When I want to get some caches in an area, etc., I use GPSBabel to query that GPX file. Groundspeak keeps tons of useful data and metadata in it’s GPX extensions that I like to have a copy of — if nothing else, I can few it while out in the field withing CacheMate.
The latest problem I had was that I had a list of caches in a CSV file in the format “lat, lon, wptname”. I wanted copy those cache entries from my main GPX file to a new GPX file (that way I can just copy those caches to a CacheMate doc). This could take some serious XML programming, but as I thought about it, I figured that there must be a way with GPSBabel. Here is what I came up with. Note that it is an assumption that the caches in the CSV file are a strict subset of the caches in the GPX file:
- Load master GPX file
- Push a copy of the GPX file on the stack
- Load the CSV file
- Filter out all the duplicates. Note that this will leave you with just the caches that aren’t in your CSV file.
- Pop the stack and append it to current list
- Again, filter out all duplicates. Note that now you will have just the caches that were in the CSV file.
- Write the GPX file
Yes, this is a takes a little to get your brain around, but it works well. Here is the GPSBabel call that did it:
gpsbabel -i gpx -f everything.gpx \ -x stack,push,copy \ -i csv -f goodcaches.csv \ -x duplicates,shortname, all \ -x stack,pop,append -x duplicates,shortname, all \ -o gpx -F goodcaches.gpx
