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

Archive

  • 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:

kml.bat:

Code:
@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.
pause

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:

Code:
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:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
   <Document>
      <name>My Photos</name>
      <open>1</open>
      <Style id="Photo">
         <geomScale>.75</geomScale>
         <IconStyle>
            <color>ffffffff</color>
            <Icon>
               <href>root://icons/palette-4.png</href>
               <x>192</x>
               <y>96</y>
               <w>32</w>
               <h>32</h>
            </Icon>
         </IconStyle>
      </Style>
      <Style id="View">
         <IconStyle>
            <color>ffffffff</color>
            <Icon>
               <href>root://icons/palette-3.png</href>
               <x>160</x>
               <y>128</y>
               <w>32</w>
               <h>32</h>
            </Icon>
         </IconStyle>
      </Style>
      <Folder>
         <name>Waypoints</name>
         <open>0</open>

2. kml-placemark.fmt:

Code:
         <Placemark>
            <description><![CDATA[
<table><tr><td>
                                <img src='$directory\$filename'
                                    width='$imagewidth' height='$imageheight'>
                                </td></tr></table>]]></description>
            <Snippet/>
            <name>$filename</name>
            <styleUrl>#Photo</styleUrl>
            <Point>
               <altitudeMode>clampedToGround</altitudeMode>
               <coordinates>$gpslongitude,$gpslatitude,0</coordinates>
            </Point>
         </Placemark>

3. kml-end.fmt:

Code:
      </Folder>
   </Document>
</kml>

- Phil

Archive

  • 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
     Wolf

Archive

  • 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