Jump to content

Creating Routes With Maps.google.com, Gmaptogpx Bookmarklet And Gpsbabel.


grnbrg

Recommended Posts

There has been a lot of focus on using Google Earth to create routes. I've worked out a series of steps that can be used to use Google Maps to do so....

 

The first step is to switch to Firefox, and add the GMaptoGPX bookmarklet to your toolbar. Information on GMaptoGPX can be found at www.elsewhere.org/journal/gmaptogpx.

 

Next, go to Google Maps, and use the "Get directions" option to create a route from one location to another.

 

Click on the GMaptoGPX bookmarklet, and after a moment, you'll be presented with the content of a gpx file with the specified route. Ignore this. If you use it, you'll find that it's actually a very coarse route, not usefull for what we want. Click on the "Full" button, and the XML data will change. This data specifies a full track of the route, and may be quite large.

 

Copy (cut and paste) this data into a file, "route.gpx" for example.

 

You now have a problem. You have a trackfile that may run to several thousand points. Geocaching.com currently does not accept track files for routing. And they'd only look at the first 500 points anyway. Enter GPSbabel. GPSbabel can be found at (surprise!) http://www.gpsbabel.org/.

 

GPSbabel, however, does not by default have an ability to convert a track to a route. It is, however, very configurable! Save (again, cut and paste) the following:

 

# gpsbabel XCSV style file
#
# Format: "GPS Babel tracktogpxroute filter"
# Author: grnbrg@grnbrg.org
#   Date: 5/07/2006
#
#
DESCRIPTION             Convert a track to a GPX 1.1 route.

# FILE LAYOUT DEFINITIIONS:
#
FIELD_DELIMITER         SPACE
RECORD_DELIMITER        NEWLINE

#
# HEADER STUFF:
#
PROLOGUE        <?xml version="1.0"?>
PROLOGUE        <gpx version="1.1"
PROLOGUE             creator="GPSBabel tracktogpxroute filter"
PROLOGUE             xmlns="http://www.topografix.com/GPX/1/1"
PROLOGUE             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
PROLOGUE             xsi:schemaLocation="http://www.topografix.com/GPX/1/1 [url="http://www.topografix.com/GPX/1/1/gpx.xsd">"]http://www.topografix.com/GPX/1/1/gpx.xsd">[/url]
PROLOGUE           <rte>

#
# INDIVIDUAL DATA FIELDS:
#
OFIELD CONSTANT, "<rtept", "%s"
OFIELD CONSTANT, "lat=", "%s"
OFIELD  LAT_DECIMAL, "", ""%f""
OFIELD CONSTANT, " lon=", "%s"
OFIELD LON_DECIMAL, "", ""%f""
OFIELD CONSTANT, ">", "%s"
OFIELD CONSTANT, "<name>", "%s"
OFIELD INDEX, "", "%04d"
OFIELD CONSTANT, "</name>", "%s"
OFIELD CONSTANT, "<cmt>", "%s"
OFIELD INDEX, "", "%04d"
OFIELD CONSTANT, "</cmt>", "%s"
OFIELD CONSTANT, "</rtept>", "%s"

# EPILOGUE: 
EPILOGUE        </rte>
EPILOGUE        </gpx>

 

to a file (tracktogpxroute.style, for example).

 

Now run the following command:

 

gpsbabel -i gpx -f route.gpx -x simplify,count=500 -o xcsv,style="tracktogpxroute.style" -F PQRoute.gpx

 

The resulting PQRoute.gpx file can be uploaded to Geocaching.com, and will provide a nice, tight match to the route you intend to travel.

 

Enjoy!

 

grnbrg.

Link to comment

Bonus points for using the style mechanism to get what you wanted. I could explain why using the xcsv writer for XML is bad idea in general case, but it probably will work for this one.

 

It's likely easier to just use the "gpxver=1.1" suboption to get (taaa daaaa) gpx 1.1.

 

But if you're going to optimize the process, why pitstop the data through GPX and the bookmarklet thingy at all? GPSBabel knows how to read the gibberish that Google Maps hocks up and it knows how to write GPX 1.1.

 

http://www.gpsbabel.org/htmldoc-development/fmt_google.html

 

Once you've saved off the page, the command to simplify it and convert it to GPX 1.1 becomes:

 

gpsbabel -i google -f googlejibberjabber -x simplify,count=500 -o gpx,gpxver=1.1 -F PQRoute.gpx

Link to comment

We do support GPX 1.1 Tracks.. are you seeing an error when trying to do this?

Ever have one of those days.... <_<

 

Looks like I missed just using the "Full" tracklog. Probably because I assumed it would truncate, but you appear to optimize the submitted route to something reasonable before truncating. My bad.

 

And my inital attempts with GPSBabel may well have omitted the gpxver="1.1" option. I found references to it, but couldn't seem to get it working. So I decided the problem was that I was feeding tracks, not routes....

 

In any event, the "Full" tracklog from GMaptoGPX results in a correct (ie: matches the roads travelled) GC.com route. No additional massaging required.

 

DOH!

 

grnbrg.

Link to comment

Bonus points for using the style mechanism to get what you wanted. I could explain why using the xcsv writer for XML is bad idea in general case, but it probably will work for this one.

 

It's likely easier to just use the "gpxver=1.1" suboption to get (taaa daaaa) gpx 1.1.

 

But if you're going to optimize the process, why pitstop the data through GPX and the bookmarklet thingy at all? GPSBabel knows how to read the gibberish that Google Maps hocks up and it knows how to write GPX 1.1.

As above to Raine -- I'm an idiot. <_<

 

The bookmarklet works for me, as I find it easier to use Google's interface to muck around until I've got a route I like, then cut and paste the data, rather than the seach co-ords. Whatever works.

 

Yeah, my style thing is a horrible (and not very general) hack. But it solves a problem I thought I needed to solve for this, and have wanted on occasion to solve for other stuff -- promoting a track to a route. (ObFeatureGrovel: Converting between tracks and routes would be nice!)

 

Thanks for a most excellent product, BTW.

 

grnbrg.

Link to comment

It's hard to declare you an idiot - it was a resourceful solution to a problem you had. That counts for a lot with me.

 

maps.google.com -> get directions -> enter start, end ->save the page and feed it to the above. I won't say it couldn't be easier but it's not terrible.

 

The problem with things like trk->rte conversions is that they're easy to do for special cases such as the one you describe. But when you support a hundred formats (ok, not all of them support tracks and routes...) there are all these goofy cases you have to think about. Route points usually have names. Trackpoint usually don't. Routepoints usually have to be unique. Trackpoints usually don't. Tracks many usually have largish numbers of control points. Routes usually don't. There are lots of sharp edges for users to hurt themselves with.

 

That said I've actually started a module a time or two to do it but keep getting frustrated that it will ultimately cause more support grief than I deserve becuase of things like the above.

 

You may or may not find the following Q&D hack inspirational. With it in place, I can do "getgpxroute place1,state place2,state > foo.gpx" and squirt foo.gpx to the website and be happy. (well, more on that in a moment.)

 

#!/bin/sh

FROM=$1

TO=$2

wget -O - "http://maps.google.com/maps?q=$FROM to $TO&output=js" |

gpsbabel -i google -f - -x simplify,count=250 -o gpx,gpxver=1.1 -F -

 

Now about that happiness thing. The stinking DAY that I cut the master for GPSBabel 1.3.0 I got a problem report that Google changed the web site in a way that breaks my reader. Fortunately, editing "™" out of the datastream is easy.

 

And you're welcome. :-)

Link to comment

Now about that happiness thing. The stinking DAY that I cut the master for GPSBabel 1.3.0 I got a problem report that Google changed the web site in a way that breaks my reader. Fortunately, editing "™" out of the datastream is easy.

Robert does this mean that GoogleLocal format is broken in 1.3.0 or that it was an easy fix for you???

Edited by PDOP's
Link to comment

Yes, it was an easy fix. It's fixed in the development tree, but I didn't get the notice until after 1.3.0 was cut, so editing away "™" is necessary for now for those that can't build from source.

 

I'm planning a maintenance release to pick up a few of these last-minute 1.3.0 glitches.

Link to comment
You may or may not find the following Q&D hack inspirational. With it in place, I can do "getgpxroute place1,state place2,state > foo.gpx" and squirt foo.gpx to the website and be happy. (well, more on that in a moment.)

 

#!/bin/sh

FROM=$1

TO=$2

wget -O - "http://maps.google.com/maps?q=$FROM to $TO&output=js" |

gpsbabel -i google -f - -x simplify,count=250 -o gpx,gpxver=1.1 -F -

For those who like to copy and paste and hope it works:

(1)Don't try this on Windows.

(2)Make sure the shell script is named getgpxroute.sh and you are in the correct folder for executing it.

(3)You have to have wget and gpsbabel installed properly.

 

I can just see somebody trying to use that with notepad...

 

@RobertLipe: I'm a newbie to shell scripting and don't know how the upload process works for geocaching,com, but would it be possible to add a line opening a browser on the upload page? (Obviously not a real url down below, but you get the idea)

http://www.geocaching,com/upload.php?file=/home/user/foo.gpx

Link to comment
Guest
This topic is now closed to further replies.
×
×
  • Create New...