KML
KML
(KML)
Eric Bohn
Keith Krupp
What is KML? How Is KML Used?
Where Did KML Come From? Where Is It Heading?
KML is a XML-based language schema describing a geographic vocabulary used by geobrowser applications
on two or three dimensional Earth maps.
KML was developed by Keyhole, Inc. along with the Earth Viewer application in 2001. Keyhole, Inc. was
acquired by Google in 2004 and KML was converted for use for the Google Earth, Google Maps and
Google Mobile applications.
The word Keyhole comes from an American military reconnaissance satellite program developed in the 1970's.
The Google Earth program both produces and consumes KML files.
KML uses the three-dimensional geographic reference system of longitude, latitude, and altitude to describe a
basic point of view in space over or on the surface of the Earth; then adds more specific control over that
view with heading, tilt, and roll factors.
KML also offers the ability to add text information, graphic overlays, 3-D polygons, paths, icons and add
embedded files (images or auditory) to enhance the experience of the geobrowser applications.
In April 2008 the 2.2 KML language specification was accepted by the Open Geospatial Consortium as the
official standard for geobrowser applications.
KML shares same structural grammar as the Geography Mark Up Language (GML) but provides more 3-
dimensional graphical functionality.
Like all XML, KML must begin with the XML header information followed by the KML root element tags. The
kml 2.2 namepace specification must be present in all KML files, and the gx namespace for Touring
elements.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2">
.
.
.
</kml>
Basic Placemark
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Gonda Building Rochester MN</name>
<description>An example of a simple placemark on known terrain.</description>
<Point>
<coordinates>-92.46651823514594,44.02303521347328,0</coordinates>
</Point>
</Placemark>
</kml>
Latitude is degrees north or south of the Equator (0 degrees). Values range from - 90 degrees to 90 degrees.
Longitude is the angular distance in degrees, relative to the Prime Meridian. Values west range from -180 to 0
degrees and east o range from 0 to 180 degrees.
Altitude is the distance of the camera from the earth's surface in meters interpreted according to the
altitudeMode element.
Heading is the direction (azimuth) in degrees from due North 0 to 360 degrees.
Tilt is the rotation in degrees around the X axis. A value of 0 indicates that the view is aimed straight down
toward the earth (default), a value for 90 indicates that the view is aimed toward the horizon, values greater
than 90 indicate that the view is pointed up into the sky. Values for are clamped at +180 degrees.
Roll is the rotation, in degrees around the Z axis. Values range from - 180 to +180 degrees
LookAt Element
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2">
<Placemark>
<name>Machu Picchu, Peru</name>
<LookAt>
<longitude>-72.503364</longitude>
<latitude>-13.209676</latitude>
<altitude>0</altitude>
<range>14794.882995</range>
<tilt>66.768762</tilt>
<heading>71.131493</heading>
</LookAt>
<styleUrl>#msn_icon12</styleUrl>
<Point>
<coordinates>-72.516244,-13.162806,0</coordinates>
</Point>
</Placemark>
</kml>
LookAt specifies the view of a virtual camera in terms of the point of interest
that is being viewed. Heading is the direction from due North in degrees.
Camera Element
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Golden Gate tour</name>
<open>1</open>
<Camera>
<longitude>-122.4790</longitude>
<latitude>37.8110</latitude>
<altitude>127</altitude>
<heading>18.0</heading>
<tilt>85</tilt>
<altitudeMode>absolute</altitudeMode>
</Camera>
</Document>
</kml>
Camera specifies the view in terms of the viewer's position and orientation.
Overlays
The The <Icon> element contains the link to the .jpg file with the overlay image. The positioning of a ground overlay is controlled by
the <LatLonBox> tag. Bounding values are given for the north and south latitudes, and east and west longitudes. Image formats
supported are JPG, BMP, GIF, TIFF, TGA, and PNG.
Paths & Styles
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Test Path</name>
<Style id="yellowLineGreenPoly">
<LineStyle>
<color>7f00ffff</color>
<width>4</width>
</LineStyle>
<PolyStyle>
<color>7f00ff00</color>
</PolyStyle>
</Style>
<Placemark>
<name>Test Path</name>
<styleUrl>"yellowLineGreenPoly"</styleUrl>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<coordinates>
-92.46649892642886,44.021611182648,0
-92.4663867057954,44.02163817950477,0
-92.46604892696915,44.02163820523538,0 -
92.46593632931734,44.02163821434633,0
-92.46571114915615,44.02163823003409,0 -
92.46548596234992,44.02163824608964,0 -
92.46533583572284,44.02163825634765,0 -
92.46514811302795,44.02161126197234,0
-92.46499818064358,44.02161125789062,0 -
A path is created by a <LineString> element.
92.46481099578385,44.02161124132853,0 -
92.46462408744513,44.02161120429276,0 -
The <tessellate> tag breaks the line up into smaller chunks, and the <extrude> tag 92.46443715040525,44.02161116735184,0
extends the line down to the ground. -92.46428760269356,44.02163815324332,0 -
92.46410061298926,44.02163811674728,0 -
When a Style and an ID is defined it can be used by Geometry, Placemarks, and 92.46395102184133,44.02166510948038,0 -
Overlays, referred to as shared styles. The Style can be referenced multiple times, 92.4637639797633,44.02166507438202,0
using the <styleUrl> element preceding the Style ID with a # sign. If the Style definition -92.46353921861345,44.02166505125623,0 -
is in an external file, include the complete URL in the <styleUrl> element. A Document 92.46346424194114,44.0216650455531,0
</coordinates>
is a container for features and styles. This element is required if your KML file uses
</LineString>
shared styles. </Placemark>
</Document>
</kml>
Highlighted Icons
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Highlighted Icon</name>
<description>Place your mouse over the icon to see it display the new
icon</description>
<Style id="highlightPlacemark">
<IconStyle>
<Icon>
<href>http://maps.google.com/mapfiles/kml/paddle/red-stars.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="normalPlacemark">
<IconStyle>
<Icon>
<href>http://maps.google.com/mapfiles/kml/paddle/wht-blank.png</href>
</Icon>
</IconStyle>
</Style>
<StyleMap id="exampleStyleMap">
<Pair>
<key>normal</key>
<styleUrl>#normalPlacemark</styleUrl>
</Pair>
Define a <Style> for the Placemark's normal icon including an <Icon> with an <href> <Pair>
to the actual image to use. <key>highlight</key>
Define a <Style> for the Placemark's highlight icon and assign an ID to it. <styleUrl>#highlightPlacemark</styleUrl>
</Pair>
Create the <StyleMap> element and assign an ID to it. The Placemark will refer to this
</StyleMap>
ID. <Placemark>
In the <StyleMap> element, specify "#normalicon" for the normal state. <name>Roll over this icon</name>
In the <StyleMap> element, specify "#highlightincon" for the highlight state. <styleUrl>#exampleStyleMap</styleUrl>
In the Placemark, add a <styleUrl> element that refers to the stylmap. <Point>
<coordinates>-122.0856545755255,37.42243077405461,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
Polygons
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>The Pentagon</name>
<Polygon>
<extrude>1</extrude>
<altitudeMode>relativeToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-77.05788457660967,38.87253259892824,100
-77.05465973756702,38.87291016281703,100
-77.05315536854791,38.87053267794386,100
-77.05552622493516,38.868757801256,100
-77.05844056290393,38.86996206506943,100
-77.05788457660967,38.87253259892824,100
</coordinates>
</LinearRing>
</outerBoundaryIs>
<innerBoundaryIs>
<LinearRing>
<coordinates>
-77.05668055019126,38.87154239798456,100
-77.05542625960818,38.87167890344077,100
-77.05485125901024,38.87076535397792,100
The polygon is made of simple inner and outer rings extruded -77.05577677433152,38.87008686581446,100
-77.05691162017543,38.87054446963351,100
down to the ground, then adding fill. -77.05668055019126,38.87154239798456,100
</coordinates>
</LinearRing>
</innerBoundaryIs>
</Polygon>
</Placemark>
</kml>
Screen Overlays
Screen overlays cannot be authored directly within Google Earth. Positioning is controlled
by mapping a point in the image specified by <overlayXY> to a point on the screen specified
by <screenXY>. In this case, the top-left corner of the image (0,1) has been made coincident
with the same point on the screen.
KMZ File
A KMZ file consists of a main KML file and zero or more supporting files that are compressed and
packaged with a zip application into an archive file with a .kmz suffix. The KMZ file can be
stored, emailed and loaded from a web server. When the KMZ file is unzipped, the main .kml file
and its supporting files are separated into their original formats and directory structure, with
their original filenames and extensions. The kml file can then be run with Google Earth.
XML Schema For KML
To validate a KML XML document download the KML XML Schema document at:
http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd
Change the following code in the ogckml22.xsd from a hard coded file location to a web link URL:
Add the xsi namespace and schemaLocation to the KML XML document you want to validate:
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/kml/2.2 ogckml22.xsd">
Google Earth:
- KML was originally developed for Google Earth
- Originally called Keyhole Earth Viewer
- Originally created by Keyhole, Inc
- Acquired by Google in 2004
- First program to view and graphically edit KML files.
- Maps the Earth by superimposing images obtained from satellite imagery,
aerial photography, and GIS 3D globe.
- Easy navigation using mouse and control button.
- Most of Earth is available in 2D imagery only, but some places have 3D available.
- 3D images of buildings and terrain are made available through digital elevation
model imagery collected by NASA’s Shuttle Radar Topography Mission.
- Able to overlay images for comparing different types of information
- Scale must be accurate, but image conforms to topography.
- Capability to build 3D models of cities
- Irish town of Westport first to do so.
- Helpful in promoting cities, and using for navigating city.
-Marble
-NASA World Wind
-Xplanet
-Earth 3D
-ESRI ArcGIS Explorer
Marble
-Virtual globe and world atlas you can use to learn more about Earth
-Mouse click on a place will bring up a wikipedia article
-Can measure distances between locations, and/or view weather
-Different “thematic” maps
- Topographic view
- Satellite view
- Night view
- Street map
-Free Open source software that promotes the use of free maps
-Can be used in C++/Qt 4.x applications
-Compatible with KML
NASA World Wind
- Developed by NASA staff and open source community members
- Uses satellite imagery and elevation data to create a 3D view of Earth
- Can be used with other planets
- Compatible with KML/KMZ with KML/KMZ plug in
http://code.google.com/apis/kml/documentation/kml_tut.html
http://code.google.com/apis/kml/documentation/kmlreference.html
http://code.google.com/apis/kml/documentation/touring.html
http://code.google.com/apis/kml/documentation/whatiskml.html
http://en.wikipedia.org/wiki/Keyhole_Markup_Language
http://en.wikipedia.org/wiki/CityGML
http://www.earth3d.org/
http://create.landprint.com/index.html
http://worldwind.arc.nasa.gov/java/index.html
http://edu.kde.org/marble/
http://www.opengeospatial.org/standards/kml