10 February 2014

Bash command line editing cheat sheet

https://www.gnu.org/software/bash/manual/bashref.html#Readline-Interaction
  • ctrl-a/e start/end of line
  • alt-f/b forward/back a word
  • ctrl-w/alt-d delete to start/end of word
  • ctrl-shift-_ undo (i.e. ctrl-underscore)
  • ctrl-y paste (yank) deleted text
    • alt-y paste older deleted text instead
  • prefix with alt+digit (0-9) to do multiple, e.g. delete two words
    • start with alt-minus to go backwards

Just a few notes I threw together for my own benefit. I finally got around to learning a bit more about editing commands on the Linux shell / terminal.

03 February 2014

Converting kml to gpx with python

Today I wanted to geo-code some of my photos.

I have an SLR digital camera (no gps of course), and an android phone. I recorded a track with My Tracks from google on the phone. (Not entirely recommended but works). I then fired up digikam to run the geo-correlation and add lat-long to the exif of the files only to discover digikam doesn't know how to read kml. Fooey.

 

I looked to gpsbabel, but it apparently can't handle this style of kml file, as differentiated by the coordinates being in the following style of markup:

<gx:Track>
<when>2014-01-25T18:00:13.955Z</when>
<gx:coord>-1.885348 50.769434</gx:coord>
<when>2014-01-25T18:00:14.565Z</when>
<gx:coord>-1.885193 50.769328 53.20000076293945</gx:coord>
<when>2014-01-25T18:00:58.566Z</when>


So I wrote a python script to munge it into gpx shape:

https://gist.github.com/timabell/8791116

This can be run as follows:

./kmlToGpx.py "25-01 12-48.kml" > "25-01 12-48.kml.gpx"

And worked a treat for me.

After I'd done this I discovered my pet tool gpsprune can open the new style kml. (I forked gpsprune a while ago and added a minor feature) However I'm glad to have a command-line tool as I have hundreds of tracks I want to convert.

Incidentally the phone can automatically sync the tracks to google drive, which is kinda handy and then you can download them from the site etc.