Keyhole Markup Language (KML)

What is KML?

KML stands for Keyhole Markup Language. It is an eXtensible Markup Language (XML) used for managing three-dimensional geospatial data in Google Earth, Google Maps and Google Maps for Mobile. It is also supported to varying degrees by other virtual Globe programs (e.g., NASA World Wind, ESRI ArcGIS Explorer). The KML 2.2 Reference has been adopted by the Open Geospatial Consortium as an international standard.

Examples and documentation on KML can be found on the official Google Earth webpages:
http://code.google.com/apis/kml/
http://earth.google.com/userguide/v4/tutorials/
http://code.google.com/apis/kml/documentation/kml_tut.html

Authoring KML

You can open a KML file with any text editor, such as Microsoft Word or Notepad on a Windows computer or vi on a Unix system. However, it is best to use a text editor that is designed for editing markup languages. If you copy and paste the sample KML code below into a text editor and save the file with a .kml extension and with UTF-8 encoding, then you will create a KML file. When creating your own KML file it must start with standard header lines:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
and end by with a closing kml tag:
</kml>

KML Elements

Between the KML designation tags are placed one or more elements that relate to various features and functionality that can be created. When an element begins with a capital letter it is a complex element. These can act as a parent elements that can contain one or child elements. When an element begins with a lowercase letter it is a simple element and can only contain character data. A tree diagram for the correct classification of elements is shown below for KML 2.2 (courtesy of Google):

Note: The abstract elements (shown in italics and in dotted boxes in the diagram) are not actually used in KML files. They are a useful way for a single element to serve as the programmatic foundation for multiple similar (but different) derived elements.

Note: Element names (contained within <>) are case sensitive

Example of KML


modis.kml



Note: Comments within KML code are indicated by <!-- Comments -->

KML vs KMZ

KMZ is a zipped version of KML. If you author KML that uses images, icons, models or textures that are stored on yor local drive, in order to share them with other uses they must be combined into a KMZ archive.

Learning KML

The following exercises act as an introduction to the major elements of KML and how to author files that utilize them. They are best followed sequentially.

  1. Points
  2. Organization
  3. Styles
  4. Multi-Points
  5. 3D Models
  6. Views
  7. Images
  8. Animation
  9. Dynamic Updating