Linux.com

Feature: Web Development

A geo-located photo album in five easy pieces

By Kevin Quiggle and Mike Whitton on July 27, 2006 (8:00:00 AM)

Share    Print    Comments   

Open standards, and openness in general, enables people to combine a variety of technologies in new and interesting ways. For example, using a camera with Exif support, a GPS receiver, the Google Maps API, and Perl, PHP and JavaScript, Mike Whitton created a Web-based photo album in which the photographs are automatically placed on a map at the exact location they were taken. Let's take a look at how this is done.

The project was inspired by, and is loosely based on, Tim Vidas' work, with numerous additional refinements. See Figure 1. to get an idea what the finished product looks like.

The project makes use of the Google Maps' "info window" feature. This feature includes the ability to created tabbed info windows, in which a map pin can represent more than one photo at a particular location. Each tab shows a different thumbnail image, clicking on the image displays a full size picture; see see Figure 2 for a sample.

Building a geo-located photo album requires five major components:

  1. Exif (Exchangeable Image File Format); the detailed standard can be found here
  2. A digital camera with support for Exif and the ability to connect to a GPS receiver
  3. A GPS receiver
  4. Google Maps API (requires an API key; click here for details)
  5. Programming: Perl, PHP, and JavaScript

The Exif format

The Exif format is a key element of this effort. Exif provides a standard method for embedding metadata tags into standard image formats such as JPEG and TIFF. The metadata tags can include information such as the date and time a picture was taken, the camera settings, and the location at which the picture was taken. Not all digital cameras support the Exif format in general, and even among those that do, few cameras support the location tag, which is crucial for our purposes.

Figure 1. Map with geo-located 'pins'
Figure 1. Map with geo-located "pins" - click to enlarge

The camera and GPS receiver

Whitton selected the Nikon D200 digital camera because it supports Exif location tags, and because it stores the data more accurately than some higher-priced models (in which the last two digits of latitude and longitude are truncated). The important lesson here is to make sure that Exif location tags are supported, but also to make sure the required level of accuracy is supported; this is a function not only of the GPS receiver, but also of the level of precision with which the data is recorded.

In addition to Exif support, the digital camera must also provide for connection to a GPS receiver. For the Nikon D200, an MC-35 GPS adapter cord is required, and of course, you must have GPS receiver which will work with a PC cable. The MC-35 connects to the GPS receiver cable, but you must purchase the PC cable along with the GPS receiver. The GPS receiver used here is a Garmin eTrex Vista, but most Garmin and Magellan GPS units with RS-232 serial outputs are compatible with the D200. If the GPS unit does not require a non-zero voltage to transmit (a D200 requirement), conforms to at least v2.01 of the NMEA 0183 protocol, and has a serial PC link cable (USB is not supported), it should work properly.

Map pin with tabbed info window
Map pin with tabbed info window - click to enlarge

When the GPS receiver is properly connected to the D200 using the Nikon MC-35 adapter and serial PC cable, the GPS indicator in the camera control panel begins to flash. When the GPS receiver is locked in (tracking a minimum of three satellites) the indicator becomes steadily illuminated, and any pictures taken are automatically tagged with the current latitude, longitude, altitude, GPS time/date stamp, number of satellites being tracked at time of picture, and map datum.

Processing the photos

Once the pictures are taken, you can upload them unmodified from the camera by FTP to the server where they are to be processed. The PHP and Perl code for the project is developed on a SUSE Linux 9.2 server, which is hosting the Web site used for project development. Readers interested in implementing a similar project can download the code from the links in this article for their own use. Whitton does picture post-processing on this server too, but this could just as easily be done on a PC.

The processing is done is two major steps: First, a Perl script retrieves the relevant Exif data from each photo and creates an XML file that contains all of the information needed to locate the "map pins" on the map, as well as to populate the info windows. Second, some PHP code generates a base map, parses the XML file, and dynamically creates the JavaScript that is used to generate the map markers and tabs. The programs use Google Maps technology; during development, Whitton used the most current version of the maps API (2.54). The latest default version of Maps API 2 is automatically used by the mapping script.

Let's look at each of the post-processing steps in more detail. The Perl script creates a list of photos to be processed, and then processes each photo in the list. It retrieves the relevant Exif data from the photo; if there is no GPS data available, the photo is skipped. If GPS data is present, it is converted from degrees/minutes/seconds to decimal degrees.

This geographic information is then used to determine the local timezone, and to convert GPS time to Unix time format. Note that the timezone script uses a time zone table typically included in all Linux distributions; the script looks for this table in /usr/share/zoneinfo/zone.tab.

The script also makes an entry to a "tab distance" array that will be used to determine if a series of photos was made at the same location. If they are, tabbed "info windows" (Google's name for the shadowed pop-ups that appear when you click on a map pin) will be created for the resulting map. The thumbnail image in the info window is generated by the camera, and is part of the Exif data. In addition, if necessary, the script will rotate the photo to horizontal. Finally, the script generates an XML file.

Following XML file creation, PHP generates a base map, parses the XML file, and generates a tab array with all required tab information. The PHP code is automatically activated when the map Web site is accessed; thus the map is dynamically created upon access. The PHP code processes the tab array to generate appropriate JavaScript for either a single info window or a tabbed info window, and the map is loaded into the Web browser.

Future developments

Although Whitton has developed the core elements of this geo-located photo album, more remains to be done. The next major improvement will be to match up the GPS location data with a database of cities, to automatically identify the city in which the photos were taken. From this information a "city index" will be generated so that all photos in the album can be sorted (and selected) by the name of the city in which they were taken, or alternatively, the closest major city. In addition, while the code generates a complete new XML file when the user accesses the map page now, in future this will be changed so that new additions are simply appended to an exisitng file.

While the camera and other hardware required for this project are relatively expensive today, we expect the price of the technology to go down in the near future. Further, the eventual implementation of GPS 3 will improve the availability and accuracy of GPS data. These developments promise exiting new capabilities in the management and presentation of geo-located photographic data.

Share    Print    Comments   

Comments

on A geo-located photo album in five easy pieces

Note: Comments are owned by the poster. We are not responsible for their content.

Timezone

Posted by: Anonymous Coward on July 28, 2006 11:16 AM
Aww, too bad. I read the bit about the timezone script and thought it accurately determined timezone from lat,long. Unfortunately, zone.tab just has the location of populous cities in the timezone, and tzfind.pl finds the closest such city. It's not at all guaranteed that that because I'm closer to New York than, say, Detroit that I'm actually in NY's timezone.

#

Another (cheaper) alternative to GPS-enable JPGs

Posted by: Anonymous Coward on July 28, 2006 07:14 PM
You can get the same results with less expensive hardware and alternative tools. Any GPS receiver with interface to PC, supported by Linux and any digital camera which tags photos via EXIF (any).

There is a program for Linux called "gpscorrelate" (<a href="http://freefoote.dview.net/linux_gpscorr.html" title="dview.net">http://freefoote.dview.net/linux_gpscorr.html</a dview.net>) which you can use to automatically tag JPG fotos taken from a camera correlating the JPG EXIF's date and time to the GPS's tracklog. Just extract the tracklog in GPX format from the GPS, load it and the images to "gpscorrelate", enter the time shift with respect to GMT, and you are done: the images get added GPS data to the appropiate locations in the EXIF header.

Then you can use the tagged photos as you will, be it with the scripts shown in the article or any other alternative, for example the GPS module for gallery2.

#

Re:Another (cheaper) alternative to GPS-enable JPG

Posted by: Anonymous Coward on July 28, 2006 08:12 PM
It's a cheaper method, but it's not really the same results. The "gpscorrelate" method matches up photo data with GPS tracklog data and is much more labor intensive (and there may not always be a match). In the method used in the article, the photo Exif file is automatically populated with GPS data as the photo is taken - there is always a match, and the GPS data is as accurate as the technology can make it.

#

How to capture image view direction (heading data)

Posted by: Anonymous Coward on July 30, 2006 05:55 PM
This sounds interesting, but I'd like to capture one more bit of data.. direction camera was pointing when the image was taken.

Often when hiking in the mountains, I'll get some nice shots of mountain walls, canyons, etc.
But when looking at them later, it is sometimes hard to determine exactly what map feature corresponds to the photo.

With the GPS coordinates I could easily get the right map location, but it would be nice to also have recorded the direction (azimuth) that the camera/gps was pointing at that moment.

I know some GPS units (ie. Garmin 76S) have internal electronic compass that could supply this data, (provided you can keep alignment between camera/receiver).
But are there any digital cameras available now that would also provide this?

Richard

#

Re:How to capture image view direction (heading da

Posted by: Anonymous Coward on August 01, 2006 12:13 AM
<a href="http://www.nikonusa.com/template.php?cat=1&grp=2&productNr=25414" title="nikonusa.com">http://www.nikonusa.com/template.php?cat=1&grp=2&<nobr>p<wbr></nobr> roductNr=25414</a nikonusa.com>

The new D2Xs now records heading in addition to the other GPS data. Since the GPS is a seperate unit the heading is relative to the direction of the GPS receiver and not the camera...

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya