Monday 28 February 2011

Wiggle No Excuses sportive 2011

thisI'm going to attempt this on 20 March


View Larger Map


If and when I make it, I'll post the Garmin Connect data.

Wednesday 16 February 2011

Creating Bike routes: Now with added python

# Help yourself to this. If you find a bug or improve on it, please let me have a copy back!
# (c) Gareth Evans Feb 2011

# Format of data is
#<coordinates>x,y</coordinates>
#or
#<coordinates>
#x,y
#</coordinates>
#or
#<coordinates>x,y
#x,y</coordinates>
#etc


#Output format is
#From:<longitude>,<latitude><n*<space>to:<longitude>,<latitude>>
#Keep first and last lines, delete 1 in n lines, so total number of lines is 25

import sys, optparse

def write (where, what):
    #print what
    where.write (what)

def printStack (output, stack):
    count = 0
    modulus = 1 + len(stack) / 22
    print  "Stack size %d mod %d "%(len (stack), modulus)
    while len (stack):
        myline = stack.pop(0)
        if count == 0:
            myline = "from:" + myline + " "
            write (output, myline)
        else:
            if not (count % modulus):  
                myline = "to:" + myline + " "
                write (output, myline)
        count += 1

    myline = "to:" + myline + " "
    write (output, myline)



def main (options, args):
    image = open(options.image, "r").readlines()
    print "len %d name %s" % (len(image), options.image)
    namebody = options.image.split('.')
    name = "output_" + namebody[0] + ".txt"
    print name
    output = open (name, "w")

    coordinate = 0
    stack = []
    print "len image %d" % len(image)

   
    while len(image):
        myline = image.pop (0)
        pos = myline.find("<coordinates>")
        #print "coords %d pos %d len image %d data %s" % (coordinate, pos, len(image), myline)

        if coordinate == 0:
            if pos >= 0:
                coordinate = 1

        if coordinate == 1:
            if pos >= 0:
                data = myline[(pos + len("<coordinates>")):].split(',')
            else:
                data = myline.split(',')
            if (len(data) > 1):
                stack.append ("%s,%s" % (data[1], data[0]))
            if myline.find("</coordinates>") >= 0:
                coordinate = 0
       
    printStack (output, stack)

if __name__ == '__main__':
    option_parser = optparse.OptionParser()
    option_parser.add_option('-i', '--image', dest='image', help=' image', default='./file.txt')
    options, args = option_parser.parse_args(sys.argv[1:])

    main (options, args)

Making bike routes

This blog will be a set of possibly interesting routes around my locale (Cambridge) but the ability to create them, if you wish, will be passed on here.

I got a Garmin Edge 500 a year ago. Although I've not REALLY got into the courses, it's about time that I did.

When I started, I created my routes in Google Maps and then, through some convoluted magic I got them on my Garmin.

Then I found that there are a lot of routes already out there, in Google Earth format (*.kml) which often go where I want but don't always start where I want. So here's the deal.

There are some limitations in Google Maps format, notably that there appears to be a limit of 25 entries. Compared to a simple 30 mile KML file which may have 400 points. You WILL have to edit your routes.

So here's the plan. You'll need to be able to run python. It's not that tricky, and I haven't included any wacky modules. I'm using python 2.6. I'll add the file in the next post.

Downloading a KML file from MapMyRide
  1. Go you your purveyor of kml files. A good one is Map My Ride or
    gpsvisualizer
  2. Find some routes that look interesting and select Export
  3. Click on Download KML 
  4. Run the python script to generate a .txt file
  5. The data in the .txt file is then copied into google maps as shown below. A route will be generated which is now editable. Remember to set the route to walking (or bike) as some routes aren't generatable
  6. Use the convoluted magic to generate first a gpx then a crs
  7. To generate the route profiles I've used gpsvisualizer to generate profiles from the KML 

I've found a new resource. Not had a proper play yet but this seems to let you edit gpx files