Cutting Edge > Teaching Methods > Teaching with Google Earth > How to Teach With Google Earth > Working with KML > KML Examples from the Google Earth Community Forums

KML Examples from the Google Earth Community Forums

An effective means of learning about KML is to open existing KML files in Google Earth to find out how they function, and then to examine the content of these files in a text editor to investigate how that functionality was implemented. Follow this up with some experimentation by editing the file in the text editor, saving it, and reloading it again into Google Earth.

A good place to find interesting KML and KMZ files is the Google Earth Community Forums. To edit a KMZ file, you can open it in Google Earth, right-click it in the Places Pane, choose Copy from the menu, and paste the contents into a text editor. In some cases, though, if the KMZ archive contains images or other locally-referenced files, this method will adjust some of the code based on the configuration of the local client machine. To guarantee that the original KML will remain intact, download the KMZ file and change the filename extension from kmz to zip. Then extract all the files and look for the KML in the doc.kml file. Following is a discussion of some examples of KML from the Google Earth Community Forums. The displayed KML code does not include the complete contents of the example files. To view the examples in Google Earth, use the attachments to the actual posts in the Forums.

Lighthouses on Novaya Zemlya? by diane9247 - Simple Placemarks


This post with its attachment initiated an interesting discussion about lighthouses that a member of the Google Earth Community noticed on the imagery for remote Novaya Zemlya.


Novaya Zemlya
Lighthouse Placemarks on the imagery for Novaya Zemlya


Below is the KML for the Placemark for Light F

<Placemark>
<name>Light F</name>
<description>This one looks taller than the others and is more obviously an open framework tower.
See post for the collection.
</description>
<LookAt>
<longitude>52.65445121235135</longitude>
<latitude>71.47225472477339</latitude>
<altitude>0</altitude>
<range>240.7937408119534</range>
<tilt>0</tilt>
<heading>0.626662975928317</heading>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
<styleUrl>#msn_ltblu-pushpin4</styleUrl>
<Point>
<coordinates>52.65420735679328,71.47244783656571,0</coordinates>
</Point>
</Placemark>

The Placemark element contains the following elements:

Names of elements in KML are case sensitive. Elements that can contain other elements are called complex elements, and their names begin with uppercase letters. Simple elements are ones that cannot contain other elements, and their names begin with lowercase letters.

San Andreas Fault Tour, 88 Places by rocdoc7 - Placemarks in a Folder for a Tour


The KMZ file attachment to this post is designed to offer a tour of the San Andreas Fault. With the file open in Google Earth, highlight the Folder that contains the Placemarks. Then click the Start Tour button. Note that the tour visits the Placemarks in order from south to north with an oblique view of each.


San Andreas Fault Tour
San Andreas Fault Tour


Following is some of the KML from the file, showing only the first three and last Placemarks. They are listed in order from south to north.

<Folder>
<name>San Andreas fault tour</name>
<open>1</open>
<Placemark>
<name>south end, Imperial Valley 1</name>
<LookAt>
<longitude>-114.6784663222666</longitude>
<latitude>32.09642998558203</latitude>
<altitude>0</altitude>
<range>172794.3706241867</range>
<tilt>53.44095890204492</tilt>
<heading>-42.79976445626162</heading>
</LookAt>
<styleUrl>#style</styleUrl>
<Point>
<coordinates>-115.2744268219582,32.59039913092694,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>lines in the hills 2</name>
<LookAt>
<longitude>-116.0397324376364</longitude>
<latitude>33.62309948128565</latitude>
<altitude>0</altitude>
<range>4534.366646633798</range>
<tilt>59.55337984658664</tilt>
<heading>-43.53757791783753</heading>
</LookAt>
<styleUrl>#style</styleUrl>
<Point>
<coordinates>-116.049122927713,33.62954588916327,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>I-10 crossing 3</name>
<LookAt>
<longitude>-116.1477941519053</longitude>
<latitude>33.70929177022048</latitude>
<altitude>0</altitude>
<range>2247.19474645383</range>
<tilt>51.97923065968305</tilt>
<heading>-43.59659600871535</heading>
</LookAt>
<styleUrl>#style</styleUrl>
<Point>
<coordinates>-116.1477941519053,33.70929177022049,0</coordinates>
</Point>
</Placemark>
.....
<Placemark>
<name>Point Delgada, last north exposure 88</name>
<LookAt>
<longitude>-124.061711289199</longitude>
<latitude>40.02930955889677</latitude>
<altitude>0</altitude>
<range>1928.375560026323</range>
<tilt>62.19365788780536</tilt>
<heading>-33.72068077249857</heading>
</LookAt>
<styleUrl>#style</styleUrl>
<Point>
<coordinates>-124.0604849710987,40.03020493258472,0</coordinates>
</Point>
</Placemark>
</Folder>

Note that each Placemark element contains a LookAt element. This controls the characteristics of the User's initial viewPoint of the location during the tour. The longitude and latitude do not always match the ones in the coordinates element but are generally close. In these Placemarks, the tilt is oblique. A 90 degree tilt would be straight down, but the oblique view affords a better look along the length of the fault.

Moore in America by SandyRichard - Placemarks with Custom Icons and Flickr Photos


Moore in America Exhibition
Moore in America


This post focuses on the Moore in America outdoor exhibition at the New York Botanical Garden. Two portions of the KML code are shown below.

<StyleMap id="msn_MoreMoore11">
<Pair>
<key>normal</key>
<styleUrl>#sn_MoreMoore11</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#sh_MoreMoore11</styleUrl>
</Pair>
</StyleMap>
<Style id="sh_MoreMoore11">
<IconStyle>
<scale>1.3</scale>
<Icon>
<href>files/MoreMoore1.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="sn_MoreMoore11">
<IconStyle>
<scale>1.1</scale>
<Icon>
<href>files/MoreMoore1.png</href>
</Icon>
</IconStyle>
</Style>

In the first portion of the KML code, one StyleMap and two Style elements are defined. The StyleMap Pairs the two styles together in preparation for one style to apply to the Placemark icons on the map while they are not highlighted and the other style to apply when one is highlighted by a mouseover. Within each portion of the Pair, these roles are specified by the key element.

<Placemark>
<name>Large Reclining Figure (#7)</name>
<description> <!--[CDATA[ <a href="http://www.flickr.com/photos/9428166@N03/2756586705/in/set-72157606688361690/" _djrealurl="http://www.flickr.com/photos/9428166@N03/2756586705/in/set-72157606688361690/" title="Large Reclining Figure (1984) by sandy richard, on Flickr"> <img src="http://farm4.static.flickr.com/3155/2756586705_9976530902.jpg" _djrealurl="http://farm4.static.flickr.com/3155/2756586705_9976530902.jpg" width="375" height="500" alt="Large Reclining Figure (1984)" /> </a>

</br>Large Reclining Figure (1984) - Sculpture #7
</br>Photo by Sandy Richard. <font color="#C93069">Click photo for Flickr photo page.</font>
</br>]]--> </description>
<styleUrl>#msn_MoreMoore11</styleUrl>
<Point>
<coordinates>-73.87560600000001,40.858599,25.90800000000001</coordinates>
</Point>
</Placemark>

This Placemark contains a styleUrl element that applies the StyleMap shown above to the Placemark. Within the description element, a url for an image of a sculpture is specified, surrounded by a hyperlink to its photo page on Flickr.

Positively 4th Street by JavaGAR - Paths


Positively 4th Street
Lower Manhattan


This post has a KMZ attachment that displays Points and Paths on the map to represent several streets. The KML for the Path that represents Bleecker Street is shown below.

<Placemark>
<name>Bleecker Street</name>
<description>
<!--[CDATA[Fog's rollin' in off the East River bank
</br>
Like a shroud it covers Bleecker Street
</br>
<a href="http://www.youtube.com/watch?v=e5UY1t47TNY" _djrealurl="http://www.youtube.com/watch?v=e5UY1t47TNY">- Simon and Garfunkel - Bleecker Street (Youtube)</a>

</br>
</br>
<a href="http://en.wikipedia.org/wiki/Bleecker_Street">Wikipedia: Bleecker Street</a>
</br>]]-->
</description>
<styleUrl>#msn_ylw-pushpin_copy1</styleUrl>
<LineString>
<tessellate>1</tessellate>
<coordinates>
-74.00575449016236,40.73707662948543,0
-74.00554191627741,40.73690625024944,0
-74.00538601097382,40.73673685526818,0
-74.00521686221545,40.73633008816115,0
-74.00456105633072,40.73401606089652,0
-74.00442116874646,40.73369229917845,0
-74.00359113655536,40.73226884473437,0
-74.00245589821969,40.73029194981276,0
-74.00220721722748,40.72989241400484,0
-74.00213793566132,40.72970906736462,0
-74.00200559260316,40.72958648484585,0
-73.99891388500097,40.72804979396432,0
-73.99442853778695,40.72581331915866,0
-73.99225549875099,40.72523919461199,0
</coordinates>
</LineString>
</Placemark>

The Path for Bleecker Street is implemented as a Placemark with LineString element. Within the LineString element are a tesselate and a coordinates element. With the value of the tessellate element set to 1, the Path will be fit to the curvature of the Earth, so that parts of it do not become hidden below ground. The coordinates element specifies the vertices of the Path, with each vertex represented by a set of three comma-delimited values, called a tuple. These values are longitude, latitude, and altitude respectively. As is the default, the latitude, which is zero in all these tuples, is given relative to ground level.

Long Island Pine Barrens by JavaGAR - Polygons


Long Island Pine Barrens
Long Island Pine Barrens

On this map, conservation zones within the Long Island Pine Barrens are bounded by Polygons. Part of the KML for one of the Polygons is shown below.

<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-72.90759486396063,40.94774696102994,0
-72.90737869343226,40.94651927329486,0
.....
-72.90759486396063,40.94774696102994,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
<innerBoundaryIs>
<LinearRing>
<coordinates>
-72.85212165009222,40.90586095968622,0
-72.85177981400211,40.90597652285753,0
.....
-72.85212165009222,40.90586095968622,0
</coordinates>
</LinearRing>
</innerBoundaryIs>
</Polygon>

This Polygon has a hole in it, so it has both an outer boundary and an inner boundary. The outerBoundaryIs and innerBoundaryIs elements each contain LinearRing elements, which in turn contain coordinates elements that list the vertices of the respective boundaries. In each of these lists of coordinates, the first and last tuple match so that the shape is closed.

World Oil Consumption by giasen - Extruded Polygons


World Oil Consumption
World oil consumption by country with prisms


The KMZ attachment to this post represents each country of the world with a three-dimensional prism. These prisms are actually elevated Polygon elements that are extended down to the ground. The height of the prism is proportional to the total oil consumption for that country represented as foot height per barrel per day divided by 10 to keep it from shooting off the screen according to CIA Factbook. The replies to the post include commentary on the effectiveness of this strategy for representing oil consumption. Several other possible methods are suggested among these comments.

<Placemark>
<name>1</name>
<styleUrl>#20730000</styleUrl>
<Polygon>
<extrude>1</extrude>
<altitudeMode>relativeToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-76.4347229003906,44.10470962524411,6318504.078090191
-76.793327331543,43.6460990905762,6318504.078090191
.....
-76.4347229003906,44.10470962524411,6318504.078090191
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>

The part of the KML for one Polygon that is shown here outlines the 48 contiguous states of the United States. The value of its extrude element is 1, meaning that it will be extended to the ground, making it into a prism. The altitudeMode is set to relativeToGround, meaning that all altitudes, which are given in meters, will be added to the elevations of the Points at which they are given to determine the absolute altitude of that vertex of the prism. The value of the coordinates element is a set of tuples that represent longitude, latitude, and altitude. Each tuple is separated from its neighbors by a whitespace. Only the first, second, and last tuples are shown here. Note that the last one is identical to the first one, which neatly closes the Polygon. For this Polygon, the altitudes are set to 6318504.078090191, which is the elevation of the upper surface of the prism representing the oil consumption of the United States.

Sumatra-Andaman Earthquake+Tsunami overlays by Georggpd - Image Overlay


Banda Aceh Overlay
Image overlay of Banda Aceh prior to the tsunami of December 26, 2004


The KMZ file attached to this post contains overlays pertaining to the Boxing Day Tsunami, which occurred in the Indian Ocean on December 26, 2004. The KML below is for the overlay of aerial imagery of Banda Aceh prior to the event.
<GroundOverlay>
<name>Banda Aceh before</name>
<visibility>0</visibility>
<Icon>
<href>images/Banda Ache before.JPG</href>
<viewBoundScale>0.75</viewBoundScale>
</Icon>
<LatLonBox>
<north>5.560702541316848</north>
<south>5.556807024958716</south>
<east>95.28900379747853</east>
<west>95.28218725198545</west>
<rotation>34.01019955693189</rotation>
</LatLonBox>
</GroundOverlay>
The LatLonBox element specifies the bounds of the overlay and the counterclockwise rotation in degrees needed to align it properly.

RUSSIA TOWER, 3D model, Norman Foster Proposal. by pivnice - 3D Model


The KMZ file attached to this post represents a 3D model composed of numerous parts. The content is divided into Folders. The first Folder can be double-clicked to provide a view of the model. Following is the KML:

<Folder>
<name>Camera</name>
<LookAt>
<longitude>37.53450937663673</longitude>
<latitude>55.75465222845214</latitude>
<altitude>0</altitude>
<range>1529.114144687669</range>
<tilt>47.2036</tilt>
<heading>357.505</heading>
</LookAt>
</Folder>

3D Model of Proposed Tower in Russia
Tower Model


The model itself contains many Polygon and LineString elements within MultiGeometry elements. A portion of one of the MultiGeometry elements follows:

<MultiGeometry>
<Polygon>
<altitudeMode>absolute</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
37.53604909910388,55.75168185832652,285.185979283664
37.53453032649647,55.75184990251844,285.185979283664
37.53450920435704,55.75185219338564,285.6859782706089
37.53604744350758,55.75168199544795,285.6859782706089
37.53604909910388,55.75168185832652,285.185979283664
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
<Polygon>
<altitudeMode>absolute</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
37.53604909910388,55.75168185832652,285.185979283664
37.53604744350758,55.75168199544795,285.6859782706089
37.53604727784002,55.75168200338794,285.6859782706089
37.53604893342639,55.75168186619818,285.185979283664
37.53604909910388,55.75168185832652,285.185979283664
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
.....
</MultiGeometry>

Education Tools. Assembling. by Valery35 - Network Link


Marine Biomes
Marine Biomes educational data from a network link


The KMZ attachment to this post is a collection of network links to popular collections of data from the Education forums of the Google Earth Community. A network link references data that is not downloaded until the user makes the network link visible by activating its checkbox in the Places Pane. The KML below is for a network link in the attachment that references data from a Google Earth Community Forums post on Marine Biomes. The href element specifies where the data resides that is downloaded when the network link is activated, and in this case it links to the attachment on the Marine Biomes post.
<NetworkLink id="khNetworkLink1133">
<name>Marine Biomes</name>
 <open>1</open>
   <Snippet id="khSnippet1134" maxlines="0" />
<description>
<!--[CDATA[Marine Biomes
Search of features by name Ctrl+F See description by Ctrl+left mouse click These data sets can be a good foundation for other jobs; you are welcome to use them in full or in part to create other collections. Generated by Valery Hronusov, Michael Barsky <a href="http://mi-perm.ru/gis/"><img src="http://mi-perm.ru/gis/images/bit.png" _djrealurl="http://mi-perm.ru/gis/images/bit.png"></a> <a href="http://mi-perm.ru/gis/">Home page</a>]]--> </description> <url> <href>http://bbs.keyhole.com/ubb/download.php?Number=347478</href> </url>
</NetworkLink>

Mt. St. Helens - Web Cam Time-lapse by pmaxfield2 - TimeStamp


Mount Saint Helens
Mount Saint Helens screen overlays with time slider


This example uses TimeStamp elements within ScreenOverlay elements to display a sequence of photographs of a minor eruption of Mount Saint Helens that occurred in 2004. The time slider controls the visibility of the photographs provided that their visibility checkboxes are checked in the Places Pane. Each ScreenOverlay represents one photograph. ScreenOverlays are connected to a fixed location on the screen even when the map view changes. Below is shown the KML for two of the overlays. The KMZ file attached to the Google Earth Community post contains a doc.kml file and a files Folder. The image files are contained in the files Folder. These images are referenced in the href elements.
 <ScreenOverlay>
 <name>StHelens - 01</name>
 <TimeStamp><when>2004-10-01T11:54:01Z</when></TimeStamp>
 <Icon>
 <href>files/Helens 20041001-1154.jpg</href>
 <refreshMode>onInterval</refreshMode>
 <refreshInterval>300</refreshInterval>
 </Icon>
 <overlayXY x="0" xunits="pixels" y="0" yunits="pixels">
 <screenXY x="0" xunits="pixels" y="0" yunits="pixels">
 <rotationXY x="0.5" xunits="fraction" y="0.5" yunits="fraction">
 <size x="0" xunits="pixels" y="0" yunits="pixels">
 </size>
 <ScreenOverlay>
 <name>StHelens - 02</name>
 <TimeStamp><when>2004-10-01T11:59:01Z</when></TimeStamp>
 <Icon>
 <href>files/Helens 20041001-1159.jpg</href>
 <refreshMode>onInterval</refreshMode>
 <refreshInterval>300</refreshInterval>
 </Icon>
 <overlayXY x="0" xunits="pixels" y="0" yunits="pixels"/>
 <screenXY x="0" xunits="pixels" y="0" yunits="pixels"/>
 <rotationXY x="0.5" xunits="fraction" y="0.5" yunits="fraction"/>
 <size x="0" xunits="pixels" y="0" yunits="pixels"/>
 </size>
</ScreenOverlay>

UFO Sightings - Time Animation by Frank4



UFO Sightings
This map of UFO reports has a timeline. Here is is shown on Google Earth 4.2, which is why the navigation controls are different from those pictured in the other examples.


This is an interesting example of the use of the Google Earth time slider that maps UFO reports through time. TimeStamp elements from three of the PlaceMarks are shown below. Note that the time can be a date without a time of day. In fact, it can consist of only a year or a year and a month.

.....
<TimeStamp><when>1948-05-10</when></TimeStamp> ..... <TimeStamp><when>1954-06</when></TimeStamp> ..... TimeStamp><when>1944</when></TimeStamp> .....

For additional information on KML, see Google's What is KML?

The New KML Interactive Sampler is a good collection of sample code, but it requires the Google Earth API plugin to be installed on the browser.


« Previous Page      Next Page »