Bundling GPS Tracks and Geographically Located Photos in KML
Submitted by dgraves on Mon, 10/19/2009 - 22:17
Recently I described my effort to add GPS data recorded during a road trip and a canoe trip to Google Maps. I had written some JavaScript to import my data into a map, with a few options for customization, but felt that there was more that could be done with the data from the canoe trip. I had a number of photographs from the trip and a desire to map them, along with the GPS data, at the positions at which they were taken. Although the photographs did not contain any meta-data providing the GPS coordinates for the location at which they were taken, they did contain meta-data indicating the time at which they were taken. Since I had a GPX file full of time associated geographic positions, I decided to fuse the two together.
This time, rather than import the GPS data and photographs directly into Google Maps, I decided to write a program to generate a KMZ file intended to be viewed with Google Earth. I felt that Google Earth, with its 3D capability, would provide a richer user experience. The program was written as a Python script which, when given a GPX file containing time-tagged GPS positions and the name of a directory containing photographs with EXIF time tags, determines the approximate location at which each image was taken. A KML file containing a KML LineString to represent the GPS track and KML Placemarks to mark the photograph locations, complete with an info bubble to display the image when clicked, is generated and packaged with the photographs in a KMZ file ready to be dragged and dropped into Google Earth for vieweing:
The program, in its current form, is intended to be run from the command prompt. It requires that the user specify the name of a GPX file and a directory containing images which are to be fused together into a KMZ file. Some optional parameters to control the generation of the KML data are also available. The full usage documentation for the program is as follows:
specify the color for the KML LineString object, default is 'ac00ffff'
-w|--line-width <width>
specify the thickness for the KML LineString object, default is 5
-s|--line-style <CONTINUOUS|SPLIT|SEGMENTED>
specify the stile for the KML LineString object as one of the following:
CONTINUOUS - All GPS track points are connected
SPLIT - all track points within a GPX track object are connected, but the tracks are not connected
SEGMENTED - all track points within a GPX track segment are connected, but the segments are not connected
default is CONTINUOUS
-i|--image-icon <image-filename>
specify the image icon for the KML Placemark
-n|--interpolate
when enabled, the position for a photograph whose time does not exactly match the time of a GPX track point will be calculated as a position between the two track points with times immediately before and after the photograph's time using simple linear interpolation; when not enabled, the position from the GPX track point with the time closest to the photograph's time will be used
-g|--group
photographs are grouped by date within the Google Earth Places list
-u|--utcoffset <seconds>
specify a time offset, in seconds, to be applied to the UTC image timestamp such that the times are adjusted to fall within a specific time zone (e.g. -14400 seconds in the Eastern time zone during daylight savings time)
-o|--output-file <filename>
specify the name of the KMZ file to be generated, defaults to the GPX filename with the .gpx extension changed to .kmz
<gpx-filename>
name of the GPX file to process (required)
<image-directory>
name of the directory containing the photograps to be processed (required)
Relevant Files
Here are links to the file containing the Python code and a sample KMZ file containing the fused canoe trip GPS data and photographs discussed by this post:
The TripConverter script has one external dependency, which provides functionality for extracting EXIF information from image files, that can be found here.