Quarter Life Crisis

The world according to Sven-S. Porst

« Similar FeetMainRandom Walks »

Geotagging

1169 words

Yikes! Geotagging probably is a mindless hype word, but it’s the kind of thing that I find interesting – particularly for image files. With geographical information at your fingertips you can’t only find your photos by folders, names or dates. But you’ll also be able to find them based on their location in the world. That’s particularly interesting as many photos – many of my photos at least – are taken when traveling, so it might enable us to keep photos from different trips to the same location together. Or, using sites like Flickr and Geobloggers, it may even enable you to see other people’s photos from the same places you’ve visited without significant effort.

Having been through the metadata war for addresses and music – i.e. those countless moments of time you spent on correcting typos, adding cover art or graphics, adding tags and so on – we know that creating metadata that are correct, uniform and precise enough can be a pain. And if it is to be done, it better require not a lot of effort. I am tempted to say that easy metadata editing and most significantly batch metadata editing is one of the big strengths of iTunes and the main reason why iTunes libraries tend to be slightly less chaotic than other digital music collections.

So I ended up thinking about making a tool that uses Google Maps to let me easily specify a location on earth and then adding that information to image files. The geographic information is stored in GPS EXIF tags and will be displayed by recent versions of iPhoto or GraphicConverter. Those applications don’t seem to offer editing of those tags, though, so my little project stalled for a while until I recently read Martin Pittenauer’s post on using PithHelmet to integrate Google Maps with geocoded images in Flickr and received a hint there pointing to ExifTool which reads and writes many metadata of image files.

It’s a Perl and command line thing. But it’s not too hard to use. So all I had to do was wrap it in an AppleScript that gets a location from a Google Map and inserts it into image files. Those Google Maps turned out to be quite messy in the way their scripts look. And I’m neither a big fan nor a big connoisseur of JavaScript, but with a bit of playing around and some helpful words from Alf it ended up being quite easy to extract the current coordinates from a Google Maps page.

After a few of the usual fights with AppleScript (which doesn’t seem to have an abs() function), I could piece all these things together to get a script that does exactly what I want. In case you’re interested in this as well, I’ll give a short rundown of what you need to do to get this on your computer. It’s not quite comfortable right now, unfortunately. So here we go:

Setup

  1. Get a copy of ExifTool and put it on your computer. If you rename the folder from that download to ‘ExifTool’ and put it in a folder named ‘bin’ in your home folder as shown in the screenshot below, the script you can download with will work right out of the box.

    Finder window showing the folder 'ExifTool' inside the folder 'bin' inside a home folder

  2. Use the frontmost tab of Safari’s frontmost window for browsing Google Maps or Wikimapia or just use Google Earth – the script has been significantly updated in July 2006!.
  3. Use iPhoto or GraphicConverter for your photos.
  4. Download my script (version 5, 31-08-2006, version history)
  5. If you put ExifTool in the location mentioned in the first step, you can skip this step.

    In you put ExifTool in a different location, you need to adapt the script so it knows where ExifTool is. Open the script in Script Editor, read the notes and change the property at the very top of the script to give the proper path to your copy of ExifTool.

  6. Possibly drop the script in some convenient location. Personally I recommend using Apple’s Script Menu that gives you a global menu for scripts. You can set it up to just display the script for use in Safari or Google Earth, say, which is probably where you want to use it.

Once the setup is done, you’re ready to use the script.

Usage

  1. Select one or several photos in iPhoto or open a single photo in GraphicConverter. Those will be the ones that are modified.
  2. Use either Google Earth or one of Google Maps or Wikimapia in Safari and locate the spot where you took the photos. Double click it, so the map centres on that exact spot and the exact coordinates will be extracted.
  3. Run the script. The geographic information will now be added to the image files’ metadata.

Caveats

Not that I’ve seen it happen, but there seems to be a slight possibility of ExifTool trashing your photos while manipulating the tags. ExifTool usually makes the tag changes in a copy of the original image. As that wouldn’t be convenient when you’re manipulating the metadata of files you have ordered before – or that you are using in iPhoto – I have set up the script to edit the files themselves. Thus be sure to have backups of the files around in case something goes wrong.

Yup, the setup process is a bit annoying right now. It should be easy to support other image manipulation applications in case they have AppleScript support. I am not too optimistic about getting it to work with Mozilla based browsers as their AppleScript support seems to be even worse than Safari’s.

There are many other little annoyances as well. Like the script itself not being user friendly and not doing error handling. Such as iPhoto apparently caching the GPS data when importing a photo and thus claiming non-existant GPS information even after you’ve added it. GraphicConverter and Preview are more mild on this. While they won’t update the EXIF information they display immediately, re-loading the file will give the expected results. (It’s a shame that Preview doesn’t do this automagically – after all Cocoa applications tend to have a certain awareness of changes to open files.)

In addition, it seems that Spotlight doesn’t index the GPS information. Which is a shame. Smart folders of photos I took in Göttingen, around Cape Town, in Las Vegas… would’ve been nice.

The final disappointment was Flickr. While there seems to be geotagging going on there and while Flickr can read the GPS data within the EXIF data, those two things seem to be unrelated and all the useful things Flickr should be doing automatically have to be done by the user or even more tools.

Fin

To sum up: What I had in mind can be done. But the way to get there isn’t as smooth as I’d like it to be. In addition, right now, the direct uses I had in mind for geographical metadata in photos – for Flickr and for Spotlight – don’t work.

August 19, 2005, 1:47

Comments

Comment by jcburns: User icon

Hi, thanks for the Applescript…pulled together several things I’ve been working with. ` I had to make one change for it to work with (I guess it has to do with US number seperators.)

on decimalToTraditionalDegrees(input) set input to my abs(input) set myDegrees to (input div 1) set a to 60 * (input - myDegrees) set myMinutes to (a div 1) set b to 60 * (a - myMinutes) set mySeconds to (b div 1)

--jcb changes below
set olddelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."         
set c to text item 2 of (b as string)
--    set c to 100 * (b - mySeconds)
set theSeconds to (mySeconds as string) & "." & c as string
set AppleScript's text item delimiters to olddelims
--end of changes

return {myDegrees as string, myMinutes as string, theSeconds}

end decimalToTraditionalDegrees

` ..so does the EXIF spec REQUIRE traditional degrees (I guess I can look up the answer to that myself.)

Thanks again!

August 20, 2005, 18:58

Comment by ssp: User icon

jcb, thanks for that.

Indeed, I only needed to insert those lines of code because of the different localisations of MacOS. AppleScript’s number to string conversion seems to always use the decimal separator as set in the system preferences. And for German systems that’s a comma by default. Unfortunately, you can’t pass the number to exiftool as it requires you to use . as a decimal separator.

I have included your improvement into the script now, so it should run properly on systems using a . as a decimal separator as well.

does the EXIF spec REQUIRE traditional degrees (I guess I can look up the answer to that myself.)

I think so. At least all EXIF reading applications I’ve seen, display the location that way. More importantly for this case, exiftool requires this kind of input, so there’s no way around it.

August 22, 2005, 0:24

Comment by erik: User icon

Very interesting, check out my blog for more information about georefrencing. the adress is http://geo.novelviews.com

November 10, 2005, 14:43

Comment by Hans Gerwitz: User icon

I’ve been trying unsuccessfully to update this to support the current version of Google Maps. On the surface, it appears modifying the Javascript to “document.title = gApplication.getMap().getCenter().toUrlValue();document.title;” would be sufficient, but I’m missing a reference somewhere.

Any chance you’ve been through this already?

May 10, 2006, 4:17

Comment by ssp: User icon

Sorry, haven’t looked at it for a while.

May 10, 2006, 9:00

Comment by Nate Silva: User icon

Google Earth supports AppleScript! I updated the script by replacing the getGoogleMapsCoordinates() function with:

    on getGoogleEarthCoordinates()
        tell application "Google Earth"
            set coords to GetViewInfo
            set long to longitude of coords
            set lat to latitude of coords
            end tell

        set newLong to decimalToTraditionalDegrees(long)
        if long > 0 then
            set eastWest to "E"
        else
            set eastWest to "W"
        end if

        set newLat to decimalToTraditionalDegrees(lat)
        if lat > 0 then
            set northSouth to "N"
        else
            set northSouth to "S"
        end if

        return {newLat, northSouth, newLong, eastWest}
    end getGoogleEarthCoordinates

July 21, 2006, 19:31

Comment by ssp: User icon

That’s excellent Nate!

I took the liberty to integrate your improvement into my script (and also add support for the nice wikimapia site as well).

July 21, 2006, 21:12

Comment by damy: User icon

How cai I reload an image in iPhoto?

July 26, 2006, 20:56

Comment by Pierre Bernard: User icon

Hi!

I can’t edit the script. Script Editor runs it rather than displaying it.

Is it compiled?

Pierre

September 26, 2006, 15:57

Comment by ssp: User icon

Odd, I just double checked and things work fine over here. I put the file into a zip archive now. Try to re-download that. Perhaps it fixes your problem (although I wouldn’t know why…).

September 26, 2006, 18:04

Comment by Don: User icon

This really sounded good until I read the part about putting the EXIF Tool in my Path. That went way over my head. I use a G5 for most of my work but beyond the desktop, even a MAC is a jungle to me.

Is there some more complete “cookbook” instruction on installing these apps? I need a “little” more detail.

Thanks,

Don

November 27, 2006, 3:11

Comment by ssp: User icon

Don, I tried clarifying the steps you need to follow above. HTH.

November 27, 2006, 17:01

Comment by Simon: User icon

As most of you I’ve been trying out solutions like this as well. Scripts like this and others which integrate GPX files and photos are great but iPhoto is the roadblock here. If you modify a photo (rotating the picture would be enough) all GPS metadata is gone. Seems that iPhoto removes this and I hate it. How can I trust the program when some of my work is lost the next time I tweak my photo?! Anyone with a solution for this?

January 9, 2007, 14:13

Comment by ssp: User icon

Yeah, iPhoto definitely isn’t good at these things :( All we can do is hope for the next version, I guess.

January 9, 2007, 16:48

Comment by Hans Gerwitz: User icon

Has anyone already set this up to work with Aperture? Using Google Earth to tag the currently selected images in Aperture would be the bee’s knees.

January 11, 2007, 2:11

Comment by ssp: User icon

Certainly not me as I don’t have a copy of Aperture.

I’m also wondering whether Aperture is better than iPhoto in recognising and preserving these metadata in your files.

January 11, 2007, 2:27

Comment by Simon: User icon

The latest version of iPhoto, I downloaded the update a few minutes ago, seems to keep the GPS tagged photos when I rotate or duplicate my photo’s which is great news. A little closer to the full GPS solution.

I’m using GPS Photo Linker to tag my photo’s (a little easier than a command line program) but I misses the iPhoto integration. I would love to see this program as an iPhoto plug-in or at least with the iPhoto selection screen instead of the finder view.

Maybe one day it would be easy to geotag your photo’s…

March 14, 2007, 22:23

Comment by Bart Busschots: User icon

I just tried to use this script on the latest version of OS X with the latest version of iPhoto and I’m sorry to say it doesn’t work :(

The script runs without obvious errors and says it has edited one photo (I only selected one) but when I look at the properties of the image the geo data is not there. I tried exiting iPhoto and starting it again to make sure the old exif data wasn’t being cached but to no effect.

I’d be REALLY interested in getting something like this working so if you could release a tweaked version for iLife ‘08 I for one would be very grateful.

Thanks for your work on this worthy project to date.

Bart.

August 26, 2007, 1:05

Comment by ssp: User icon

Bart, I do not have iPhoto ’08, so I can’t really try things out at this stage. However, if iPhoto ’08 is like iPhoto 6 and the ‘looking at the properties’ you mention refers to the information window for a photo in iPhoto itself, then I wouldn’t expect the updated GPS information to show up there even if writing it had worked. iPhoto 6 seems to read that information once when it imports the photo and then just keeps displaying the values (or the lack of values) it found at that time even if things have been updated.

The first thing you should try is dragging a photo you ran the script on to the Preview application and checking whether the GPS information is displayed there in the Details tab of the information panel. In iPhoto 6 at least, it will be. So with a bit of luck this is also the case for iPhoto ’08.

August 26, 2007, 11:17

Add your comment

« Similar FeetMainRandom Walks »

Comments on

Photos

Categories

Me

This page

Out & About

pinboard Links

People

Ego-Linking