Month: October 2008

How to use IGC data to geotag your photos

Posted by on October 7, 2008

When taking photos on a cross-country flight it’s not always easy to remember where they were taken. And wouldn’t it be cool to look at your photos on flickr’s map?
Either you buy a camera with an integrated GPS receiver which automatically stores a geotag in your picture file’s meta data or you use GPS data that’s gathered anyway: Your IGC files.
What do you need?

Both programs are available for both Linux and Windows. My article is focused on Linux but the commands on windows will be quite similar. If you are running Debian or Ubuntu you can install these via

apt-get install gpscorrelate gpscorrelate-gui gpsbabel

The GPS Photo Correlator accepts GPS data in the GPX format. So you will need to convert your data into that format:

gpsbabel -i igc -o gpx <infile>.igc <outfile>.gpx

Now lets geotag your files:

gpscorrelate -g <gpxfile> -z +2:00 --show <file(s)>

“-z +/-XX:XX” is needed because the timestamp on your photos is probably not UTC.
<file(s)> is either a list of files (”DSC2131.JPG DSC2322.JPG”) or a wildcard expression (”*” for all photos in the directory or something like “DSC12*.JPG”).
If you add “–no-write” no EXIF data will be written and you can check if your photos would have been tagged right.

If you want flickr to use your photos’ EXIF geotags you have to change your account settings.

Optimistic Locking for Datamapper

Posted by on October 1, 2008

Update(2009-3-3): dm-optlock now on github

Update(2009-1-10): New version

I should be learning for my test on next tuesday, but coding helps keeping me in a good mood.
Here is a little gem I will need in a future project for which I’ve choosen merb + datamapper. Datamapper doesn’t support any row level locking.
My code checks if the record you want to save was changed since you loaded it. If it was changed it raises an exception (DataMapper::StaleObjectError). It works quite like ActiveRecord’s optimistic locking.
You need to define this column in your model you want to be locked:

property :lock_version, Integer, :default => 0

Anywhere in your code where you update your objects you should be prepared to handle the exception:

begin
  if @obj.update_attributes({:dummy => 123})
    #successful
  else
    #validation errors?
  end
rescue DataMapper::StaleObjectError
  #tell the user that he was too slow
  #or even better: show him the conflicts and let him merge the changes
end

The gem can be downloaded here:
dm-optlock-0.1.0.gem
Please let me know what you think of it. I’ll try and put it on RubyForge, too.

(00:27) Little update:
I added a ’set_locking_column’ method.
dm-optlock-0.1.2.gem

Update:
dm-optlock is on Rubyforge.
Now you can get it like this:

gem install dm-optlock