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 learn more about KML and KMZ files is KML Tutorial. Another place to become more expert with Google Earth is Google Earth Outreach's Learn Site.
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.
2020 Update: the following links to files do not work because the original Google Earth Community Forums have been discontinued but the information about working with KML files is still helpful.
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.
Below is the KML for the Placemark for Light F
Light F
This one looks taller than the others and is more obviously an open framework tower.
See post for the collection.
52.65445121235135
71.47225472477339
0
240.7937408119534
0
0.626662975928317
relativeToGround
#msn_ltblu-pushpin4
52.65420735679328,71.47244783656571,0
The Placemark element contains the following elements:
- name - This serves as a label for the Placemark in the 3D Viewer and in the Places Pane. It also appears at the top of the information balloon for the Placemark.
- description - This appears in the information balloon for the Placemark.
- LookAt - This determines the initial view of the Placemark when it is double-clicked in the Places Pane of the 3D Viewer.
- styleUrl - This refers to the StyleMap defined in the Document element that contains the Folders and Placemarks in this file. The StyleMap specifies what Style elements apply to the Placemark in normal and highlight modes.
- Point - This is the geographic location of the placermark icon.
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.
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.
San Andreas fault tour
1
south end, Imperial Valley 1
-114.6784663222666
32.09642998558203
0
172794.3706241867
53.44095890204492
-42.79976445626162
#style
-115.2744268219582,32.59039913092694,0
lines in the hills 2
-116.0397324376364
33.62309948128565
0
4534.366646633798
59.55337984658664
-43.53757791783753
#style
-116.049122927713,33.62954588916327,0
I-10 crossing 3
-116.1477941519053
33.70929177022048
0
2247.19474645383
51.97923065968305
-43.59659600871535
#style
-116.1477941519053,33.70929177022049,0
.....
Point Delgada, last north exposure 88
-124.061711289199
40.02930955889677
0
1928.375560026323
62.19365788780536
-33.72068077249857
#style
-124.0604849710987,40.03020493258472,0
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
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.
normal
#sn_MoreMoore11
highlight
#sh_MoreMoore11
<br> <IconStyle><br> <scale>1.3</scale><br> <Icon><br> <href>files/MoreMoore1.png</href><br> </Icon><br> </IconStyle><br>
<br> <IconStyle><br> <scale>1.1</scale><br> <Icon><br> <href>files/MoreMoore1.png</href><br> </Icon><br> </IconStyle><br>
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.
Large Reclining Figure (#7)
#msn_MoreMoore11
-73.87560600000001,40.858599,25.90800000000001
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
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.
Bleecker Street
#msn_ylw-pushpin_copy1
1
-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
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
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.
-72.90759486396063,40.94774696102994,0
-72.90737869343226,40.94651927329486,0
.....
-72.90759486396063,40.94774696102994,0
-72.85212165009222,40.90586095968622,0
-72.85177981400211,40.90597652285753,0
.....
-72.85212165009222,40.90586095968622,0
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
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.
1
#20730000
1
relativeToGround
-76.4347229003906,44.10470962524411,6318504.078090191
-76.793327331543,43.6460990905762,6318504.078090191
.....
-76.4347229003906,44.10470962524411,6318504.078090191
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
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.
Banda Aceh before 0 images/Banda Ache before.JPG 0.75 5.560702541316848 5.556807024958716 95.28900379747853 95.28218725198545 34.01019955693189
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:
Camera
37.53450937663673
55.75465222845214
0
1529.114144687669
47.2036
357.505
The model itself contains many Polygon and LineString elements within MultiGeometry elements. A portion of one of the MultiGeometry elements follows:
absolute
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
absolute
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
.....
Education Tools. Assembling. by Valery35 - 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.
Marine Biomes 1 http://bbs.keyhole.com/ubb/download.php?Number=347478
Mt. St. Helens - Web Cam Time-lapse by pmaxfield2 - TimeStamp
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.
StHelens - 01 2004-10-01T11:54:01Z files/Helens 20041001-1154.jpg onInterval 300 StHelens - 02 2004-10-01T11:59:01Z files/Helens 20041001-1159.jpg onInterval 300
UFO Sightings - Time Animation by Frank4
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.
.....
1948-05-10 ..... 1954-06 ..... TimeStamp>1944 .....
For additional information on KML, see Google's What is KML?
The New KML Interactive Sampler is a good collection of sample code.