Author Topic: Generating a Google Earth KML file  (Read 4109 times)


  • Newbie
  • *
  • Posts: 0
Generating a Google Earth KML file
« on: May 12, 2010, 08:54:01 AM »
[Originally posted by exiftool on 2007-02-14 15:02:30-08]

Here are some simple steps which use ExifTool to generate a
KML file for Google Earth from a set of images with embedded
GPS information:

First you need a set of 3 files to make up the framework of the
KML file.  These files are included at the bottom of this post:

1. kml-start.fmt - the header section of the KML file

2. kml-placemark.fmt - the section that is repeated for each image

3. kml-end.fmt - the end section of the KML file

The second of these files contains the necessary ExifTool formatting
codes to insert the file name, size and GPS coordinates into the KML file.

The steps to generating a complete KML file are:

a) Copy kml-start.fmt to your output file.

b) Concatenate the output of "exiftool -n -r -q -p kml-placemark.fmt DIR"
to the file, where "DIR" is the full directory specification for the images.

c) Concatenate kml-end.fmt to the output file.

d) You can now open the output KML file in Google Earth.

In Windows, this can be automated with a simple batch file to give a
drag-and-drop utility to peform these steps:


@echo off
type c:\windows\kml-start.fmt > c:\out.kml
exiftool -n -r -q -p c:\windows\kml-placemark.fmt %* >> c:\out.kml
type c:\windows\kml-end.fmt >> c:\out.kml
echo done.

The above commands assume that the KML format files are in
the c:\windows directory and that exiftool is somewhere in your
PATH (ie. also in c:\windows).

You should be able to drag and drop geocoded images and folders
containing images onto this batch file to generate the output file
c:\out.kml, which can be opened in Google Earth.

In Unix (and Mac OS X), the commands are slightly different:

cat kml-start.fmt > out.kml
exiftool -n -r -q -p kml-placemark.fmt DIR >> out.kml
cat kml-end.fmt >> out.kml

(assuming the KML format files are in the current directory)

Here are the 3 KML format files:

1. kml-start.fmt:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="">
      <name>My Photos</name>
      <Style id="Photo">
      <Style id="View">

2. kml-placemark.fmt:

                                <img src='$directory\$filename'
                                    width='$imagewidth' height='$imageheight'>

3. kml-end.fmt:


- Phil


  • Newbie
  • *
  • Posts: 0
Re: Generating a Google Earth KML file
« Reply #1 on: May 12, 2010, 08:54:38 AM »
[Originally posted by runningwolf on 2009-07-09 16:45:33-07]

Hi Phil,

This is Cool. I managed to get it running.
However, a slight thing I'm missing:
If I apply this to a pic without geo infortmation in it, my batch continues and launches Google Earth in Nirvana. Is there a chance to check a returncode (e.g. %errorlevel%) in order to see if it makes sense to continue? I mean exiftool display a warning message saying that it's missing longitude. But how can I verify this fact in my batch?

Again, thanks a lot for this


  • Newbie
  • *
  • Posts: 0
Re: Generating a Google Earth KML file
« Reply #2 on: May 12, 2010, 08:54:38 AM »
[Originally posted by exiftool on 2009-07-09 17:31:11-07]

Hi Wolf,

The errorlevel is not set in this case, so we must figure
out another way.  You could maybe do someting like
grep for "coordinates" in the output file before launching
Google Earth.  Or if you are doing multiple files, you
could add a -if option to exiftool to prevent
it from parsing files which don't contain GPS information.

Just a couple of ideas.  There are probably other ways
around this problem.

- Phil