# XML - Managing Data Exchange/Google earth

## KML Introduction

(most content here is directly quoted from the KML wikipedia
article)

**KML** (**K**eyhole **M**arkup **L**anguage) is an XML-based Markup
language for managing the display of three-dimensional geospatial data
in the programs Google Earth, Google Maps, Google Mobile, ArcGIS
Explorer and World Wind. (The word *Keyhole* is an earlier name for the
software that became Google Earth; the software was produced in turn by
Keyhole, Inc, which was acquired by Google in 2004. The term \"Keyhole\"
actually honors the KH-11\|KH reconnaissance satellites, the original
eye-in-the-sky military reconnaissance system now some 30 years old.)

The KML file specifies a set of features (placemarks, images, polygons,
3D models, textual descriptions, etc.) for display in Google Earth, Maps
and Mobile. Each place always has a longitude and a latitude. Other data
can make the view more specific, such as tilt, heading, altitude, which
together define a \"camera view\". KML shares some of the same
structural grammar as Geography Markup
Language\|GML1. Some KML information
cannot be viewed in Google Maps or Mobile
2.

KML files are very often distributed as **KMZ** files, which are Data
compression\|zipped KML files with a .kmz extension. When a KMZ file is
unzipped, a single \"doc.kml\" is found along with any overlay and icon
images referenced in the KML.

Example KML document:

``\
` <?xml version="1.0" encoding="UTF-8"?>`\
` <kml xmlns="http://earth.google.com/kml/2.0">`\
` <Placemark>`\
`   <description>New York City</description>`\
`   <name>New York City</name>`\
`   <Point>`\
`     <coordinates>-74.006393,40.714172,0</coordinates>`\
`   </Point>`\
` </Placemark>`\
` </kml>`

The MIME type associated to KML is
*application/vnd.google-earth.kml+xml*.\
The MIME type associated to KMZ is *application/vnd.google-earth.kmz* .

## Basic KML Document Types

For an XML document to recognize KML specific tags you must declare the
KML namespace (listed below).

`<kml xmlns="http://earth.google.com/kml/2.0">`{=html}

You will see this declaration in all the example files listed.

In order to see use the examples provided in this chapter you will need
to copy and paste the text into any text editor. Next you will save the
file as a .kml. This can be done by choosing \"save as\" and naming the
file with a .kml extension (You might have to surround the name in
quotes ie \"test.kml\").

### Placemarks

Placemarks simply make a clickable pinpoint inside Google Earth at an
exact location based on coordinates. This can be useful for marking a
point of interest or a beginning and ending destination to a trip.

The example KML document in the introduction uses the Placemark tag. If
you want to move the placemark to a different location all you would
change are the coordinates.

### Paths

Paths are a series of connected coordinates that can be edited with line
styles for a more bold appearance inside Google Earth. The height and
color can be adjusted for a more exaggerated appearance and better
clarity.

The following example is a path from Atlanta, Georgia to Nashville,
Tennessee. The code may look a bit complicated but it is mostly just
styling/formatting tags with the 4 actual coordinates at near the end.
So if you wanted to use the same style wall but just make a different
path, all you would do is change the coordinates.

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://earth.google.com/kml/2.1">

      <Document>
        <name>Paths</name>
        <description>Path from Atlanta to Nashville</description>

        <Style id="yellowLineGreenPoly">
          <LineStyle>
            <color>7f00ffff</color>
            <width>4</width>
          </LineStyle>
          <PolyStyle>
            <color>7f00ff00</color>
          </PolyStyle>
        </Style>

        <Placemark>
          <name>Atlanta to Nashville</name>
          <description>Wall structured path</description>
          <styleUrl>#yellowLineGreenPoly</styleUrl>
          <LineString>
            <extrude>1</extrude>
            <tessellate>1</tessellate>
            <altitudeMode>absolute</altitudeMode>
            <coordinates>
            -84.40204442007513,33.75488573910702,83269
            -84.37837132006098,33.82567285375923,83269
            -84.79700041857893,35.30711817667424,83269
            -86.79210094043326,36.15389499208452,83269 
            </coordinates>
          </LineString>

        </Placemark>
      </Document>
    </kml>

### Overlays

Overlays are graphics that can be placed over an area in Google Earth
marked by coordinates. These graphics can show how an area looked at a
different point in time or during a special event (like a volcanic
eruption).

This overlay example comes from Google\'s KML samples webpage and shows
what Mt. Etna looked like during an actual eruption.

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://earth.google.com/kml/2.1">
      <Folder>
        <name>Ground Overlays</name>
        <description>Examples of ground overlays</description>
        <GroundOverlay>
          <name>Large-scale overlay on terrain</name>
          <description>Overlay shows Mount Etna erupting 
              on July 13th, 2001.</description>
          <Icon>
            <href>http://code.google.com/apis/kml/documentation/etna.jpg</href>
          </Icon>
          <LatLonBox>
            <north>37.91904192681665</north>
            <south>37.46543388598137</south>
            <east>15.35832653742206</east>
            <west>14.60128369746704</west>
            <rotation>-0.1556640799496235</rotation>
          </LatLonBox>
        </GroundOverlay>
      </Folder>
    </kml>

You can see from the code that it takes the image etna.jpg and places it
over the coordinates listed.

### Polygons

Polygons are a neat feature of Google Earth that allow 3-D shapes to be
molded anywhere in Google Earth. These shapes can be useful for making
neat presentations or just showing the world a structure actually looks.

This example is a polygon of Turner Field (The Atlanta Braves\' home
stadium) in Georgia. There is no styling on the polygon to keep the code
simple.

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://earth.google.com/kml/2.1">

      <Placemark>
        <name>Turner Field</name>
        <Polygon>
          <extrude>1</extrude>
          <altitudeMode>relativeToGround</altitudeMode>
          <outerBoundaryIs>
            <LinearRing>
              <coordinates>
                    -84.39024224888713,33.73459764262901,28
            -84.38961532726215,33.73451197628319,28
            -84.38830478530726,33.7350571795205,28
            -84.38811742696677,33.73579651137399,28
            -84.38856034410841,33.73618350237595,28
            -84.38930790023139,33.73647497375488,28
            -84.38997872537549,33.73655338302832,28
            -84.39051294303495,33.73605785090994,28
            -84.39056804786146,33.73528763589146,28
            -84.39024224888713,33.73459764262901,28
         </coordinates>

            </LinearRing>
          </outerBoundaryIs>      
        </Polygon>
      </Placemark>
    </kml>

As you can see from the code, the polygon\'s 3-D shape is made up from
the latitude and longitude coordinates with the height being determined
by the 3rd column value inside the coordinates tag (28 in this case).

## Google Earth

Google Earth is the name of Google\'s free software that is responsible
for handling these KML documents. It is a virtual world created by a
collage of satellite images where a user can manipulate the Earth in any
way to see its landscapes, oceans, and cities.

You can find more information and download the software
here.

### Basic Interface Navigation

The user interface is fairly straight forward and is extremely easy for
computer illiterate users to just jump right in and start exploring. You
can completely ignore the toolbars and buttons if you want and just
click and grab on the Earth to shake, spin, or roll it as you please. To
zoom in, simply right-click and pull down or up depending on the speed
which you prefer to \"fall\" toward the surface.

If you would like help finding a location you can type in the location
(in the form of City, State) in the \"Fly to..\" search box. Google
Earth will then spin around and zoom in to the location entered. If you
want to take a virtual vacation, Google has some preset locations saved
in the window below \"Fly to\...\" labeled \"Sightseeing.\" Simply click
on one of these locations and be taken to the location where pictures,
articles, and comments can be all be viewed.

### Points of Interest

Points of interest that Google has already marked for users are marked
with different color dots and icons. These can be clicked on for a
variety of information ranging from a simple comment, to a panoramic
photograph of that exact location. Advanced users, interested in the
code make-up of such a feature, can right click on any of Google\'s
marks and choose \"Copy.\" This will copy all the code for that feature
where you can just paste it into a text document to see all of the tags
and references.

## More References

### External links

-   KML Documentation
-   Developer Knowledge Base: KML in Google
    Earth
-   KML Developer Support
    group
-   KMLImporter
    importing placemarks into NASA World
    Wind
-   Use hierarchical maps (Mindmaps) to create
    and manage KML files and convert Excel
    data to KML.
-   Google Earth Connectivity
    Add-on
    for ArchiCAD 9

### Other notes

-   Point of Interest
-   Geography Markup
    Language

### Wikipedia in other languages

-   w:ar:كيه إم إل (Arabian)
-   w:de:Keyhole Markup
    Language (German)
-   w:es:KML (Spanish)
-   w:it:Keyhole Markup
    Language (Italian)
-   w:hu:Keyhole Markup
    Language (Hungarian)
-   w:nl:Keyhole Markup
    Language (Dutch)
-   w:pl:Keyhole Markup
    Language (Polish)
-   w:ru:KML (Russian)

:   /Exercises/

