I want to make a small break in my usual Silverlight and Windows Presentation Foundation posts and talk about a technology holy grail I just achieved: Automatically geocoding the pictures I take before I post them to Flickr (or any other photo service, for that matter). I have been wanting to do that for a long time, and only recently achieved this. Let’s see how.
First, let’s define what geocoding is: It is the process of encoding the geographical coordinates (long, lat) of the location in which a picture was taking, directly inside the picture file.
This is not the same as geotagging, which is the process of encoding these coordinates outside of the picture file, for example in Flickr tags. When you post a picture on Flickr, you can position this picture on a map, and the location will automatically appear in the picture’s tags. However, if you download this picture, the information is lost. In the contrary, geocoding will save the location directly in the file, and so it will be kept. Thankfully, Flickr doesn’t only understand geotagging, it is also able to read information geocoded in a picture file, if you set it up to do so (we will see how in just a moment).
To geocode a location in a picture file, we use something called EXIF, which is a kind of meta data encoded inside a JPG file or other formats. This is for example where you find the date and time at which the pictures were taken, the camera brand, if the flash was used or not, etc… EXIF is a standard which is very convenient. Writing an application reading and even writing EXIF information is not very difficult in .NET, in fact I did that some time ago for a web application I was working on.
Setting up Flickr to understand geocodes
As I said, Flickr is able to understand geocodes encoded in an EXIF header, but you must set it up to do so. This is very easy:
- Navigate to your Flickr account and sign in
- Under “You”, select “Your account”
- Choose the tab “Privacy and permissions”
- Scroll down until you find “Import EXIF location data” and set it to yes.
This setting is off by default, because some pictures are automatically geocoded, and you may not want to share this information with everyone just like that.
Getting the geographical information
The main issue we have here is that most cameras on the market don’t have a GPS built in. Some cameras do, however, and you can get the geo information directly encoded in the pictures as they are taken. This is obviously the easiest way, and then you just need to upload the pictures to Flickr to see them appear on the map.
However, if you don’t have a GPS-camera, you can use a GPS recorder to acquire the geographical data. While some GPS modules allow you to do that, I used my Nokia E71 to fulfill this operation. This phone has a built in GPS that you can use to visualize your location at all times. This alone is still not enough to record the data, though, and this is where the Nokia research labs help you: A free application called Nokia Sports Tracker exists, that you can download and install from here:
This app is very easy to install, and lets you record “sport activities”, which in our case are not very sportive, but nevermind.
- Before you start, make sure that the clock on the camera and the clock on the phone are synchronized. This is important because we will use the timestamp to get the picture’s location. Note that if you forget this, you can correct the time difference later.
- Start the Nokia Sports Tracker application on your E71.
- Select a New Workout
- Set the options. Depending on your activity, you can for example select
- Activity: Walking
- Live sharing: No
- Route: None
- Autolap: Off
- Target: None
- Replay: None
- Press on OK and then on Start. Your position will now be recorded. You can leave the recording run in the background. Last time I tried, I recorded for more than 5 hours without a glitch.
This part is pretty straightforward :)
Exporting the geo data
You need to save the geo information to a file so that you can save it to your computer. After you stop the “workout”, you can retrieve it at any time by starting the application again and selecting “Training diary”, and then the date of the data you want to export.
Then choose the correct data set. You can see diverse info such as a summary of the data, and even a track showing the way you walked/drove/etc. Note that no map is displayed at the time, but apparently this is something that Nokia is working on.
Then, simply select Options / Export. You can choose a number of format, including CSV, plain old XML, Google Earth (KML) or GPX. This is the format you want to choose now. The easiest is to save the file on the memory card, it makes it easier to import it on your PC later.
Now you’re back home, and need to match the pictures with their location. My first move was to start writing a small application to do that, but then I realized that something probably already existed, and I was right. There is an open source application on Google Source available that will do just that: gpicsync (http://code.google.com/p/gpicsync/).
This app allows you to match the timestamps of the recorded locations in the GPS file on one hand, and the timestamps of the pictures you took on the other hand. This is why it was important to synchronize the clocks of the phone and of the camera.
After installing the application, start it. It is a very simple app and was obviously developed by non professional software developers (the UI is quite painful to look at and doesn’t resize correctly) but it does the job and is free, which is all we ask from it.
- Under Options, you can correct a possible time difference between the GPS and the camera.
- Select “Pictures Folder” to set in which folder the pictures you want to geocode are saved.
- Select the GPX file you saved before.
- If you want to use the pictures in Google Earth later, you can set the corresponding options.
- Finally, press “Synchronize”.
- After the encoding has been done, and if Google Earth is installed on your system, you can even visualize the file, your route and the pictures in this application. This is a nice touch.
Uploading to Flickr
This part is easy too. Simply upload the pics, et voila, you can now see them directly on the Flickr map.