Keyhole Markup Language
Keyhole Markup Language (KML) is an XML-based notation for expressing geographic annotation and visualization, enabling the display of features such as points, lines, polygons, images, and 3D models on two-dimensional maps and three-dimensional Earth browsers.[1]
Originally developed by Keyhole, Inc., as a proprietary format for its Earth Viewer software, KML was introduced to support interactive geospatial data sharing and visualization over the internet.[2] In 2004, Google acquired Keyhole, Inc., integrating the technology into its platforms and rebranding Earth Viewer as Google Earth, which popularized KML for creating and sharing custom geographic content.[3]
Google submitted KML to the Open Geospatial Consortium (OGC) for standardization in 2007, leading to its adoption as an official OGC standard in 2008 with version 2.2, which harmonized it with other geospatial standards like Geography Markup Language (GML).[1] Subsequent versions, including 2.3, have expanded support for advanced features while maintaining backward compatibility.[1]
KML's key features include hierarchical data structures for organizing geographic elements, support for styling and theming (e.g., colors, icons, and labels), time-based animations, and network links for dynamic content retrieval.[4] It is widely used in applications beyond Google Earth, such as ArcGIS and QGIS, for tasks including overlaying data on satellite imagery, route planning, and environmental monitoring, promoting interoperability across geospatial tools.[5]
Introduction
Definition and Purpose
Keyhole Markup Language (KML) is an XML-based schema designed for expressing geographic annotations and visualizations in two-dimensional maps and three-dimensional Earth browsers.[1] It originated from the EarthViewer software developed by Keyhole Inc., which was acquired by Google in 2004, leading to its integration into Google Earth.[2] KML serves as an open standard maintained by the Open Geospatial Consortium (OGC), facilitating the encoding and transport of geographic data for display in compatible applications.[1]
The primary purpose of KML is to store and represent various geographic elements, including locations (points), paths (lines), polygons, images (overlays), and 3D models, enabling users to annotate and visualize spatial information effectively.[6] It supports the creation of placemarks to highlight specific sites, tours to guide users through narrated sequences of views, and network links to dynamically fetch and integrate external KML content from remote sources.[1] These capabilities make KML ideal for applications ranging from personal mapping to scientific data sharing, allowing seamless exchange of geospatial information across platforms.[1]
Key features of KML include support for styling to customize the appearance of geographic elements, such as colors and icons for placemarks or line widths for paths; timestamps to associate time-based data with features, enabling animations like historical imagery or tracked movements via time sliders; and camera views to define precise observer perspectives, including orientation and altitude for immersive navigation.[1][7][4] These elements allow KML files to control not only what geographic data is displayed but also how users interact with and navigate through it in Earth browsers.[1]
Development History
Keyhole, Inc. was founded in 2001 in Mountain View, California, by John Hanke and a team of engineers with backgrounds in satellite imagery and visualization software.[8] The company developed Keyhole Markup Language (KML) as an XML-based format to handle and display geospatial data within its flagship product, EarthViewer 2.0, which allowed users to interact with 3D satellite imagery and terrain models over the internet.[2] This initial implementation of KML focused on enabling placemarks, paths, and overlays to visualize locations and routes, marking the beginning of a proprietary system for geospatial annotation.[9]
In October 2004, Google acquired Keyhole, Inc. for an undisclosed amount, integrating its technology into Google's ecosystem to enhance mapping capabilities.[10] The acquisition paved the way for the public release of Google Earth in June 2005, which adopted KML as its core file format for user-generated content and data interchange.[11] With this launch, KML version 2.0 was introduced, supporting expanded features such as nested folders, styles, and network links for dynamic content updates, and it underwent refinements through subsequent Google Earth releases to improve compatibility and performance.[6]
Recognizing the need for broader interoperability, Google submitted KML to the Open Geospatial Consortium (OGC) in early 2007, initiating a standards development process.[12] By April 2008, KML 2.2 was approved as an official OGC standard, transitioning it from a proprietary format to an open international specification while maintaining backward compatibility.[13] In October 2015, KML 2.3 was adopted as an updated OGC standard, adding support for advanced features such as improved 3D modeling and extensions.[14]
Following its standardization, KML has seen minor enhancements integrated into Google Earth updates, with ongoing support for advanced 3D modeling through features like photogrammetry-derived buildings and terrain extrusion up to version 7.3 in 2017 and beyond via web-based iterations.[15] These developments have included cloud-based integration to support collaborative mapping and AI-driven visualizations, with updates as of 2024 enabling import and storage of KML datasets in Google Earth projects via Google Drive for enhanced analysis.[16]
Syntax and Structure
Core Elements and Schema
Keyhole Markup Language (KML) is structured as an XML 1.0 application, adhering to the XML schema outlined in the Open Geospatial Consortium (OGC) KML 2.3 Encoding Standard, with the core schema defined in ogckml23.xsd.[1] This schema enforces a namespace of http://www.opengis.net/kml/2.2 for standard elements (maintained for backward compatibility), ensuring interoperability in geographic data representation.[17] Google extensions, which build upon the OGC core, are defined in the additional schema kml22gx.xsd under the namespace http://www.google.com/kml/ext/2.2, but the fundamental structure remains rooted in the OGC specification.[4]
The root element of any KML document is <kml>, which serves as the container for all content and must include the appropriate xmlns attribute to reference the schema.[4] Within this root, KML documents typically include <Document> elements to group related features or standalone <Placemark> elements for individual geographic annotations.[1] The <Placemark> element is the primary building block for representing spatial features, such as points of interest, paths, or areas; it can contain descriptive metadata like <name> and <description>, along with a geometry element and optional styling.[4]
Geometry in KML is specified through elements that extend the abstract <Geometry> type in the schema, including <Point> for single locations, <LineString> for linear paths composed of connected segments, and <Polygon> for enclosed areas defined by an outer boundary and optional inner boundaries (using <LinearRing>).[17] Coordinates within these geometries are provided via the <coordinates> element, which requires tuples in the order longitude, latitude [,altitude], expressed in decimal degrees for longitude (-180 to 180) and latitude (-90 to 90), with altitude in meters relative to the WGS84 datum if specified.[4] Multiple coordinate tuples are separated by spaces, and the schema mandates comma separation within each tuple without intervening spaces; altitude is optional and defaults to clamping to the ground if omitted.[1] Positioning modes are controlled by the <altitudeMode> attribute on geometry elements, supporting values such as clampToGround (default, snaps to terrain), relativeToGround (height above terrain), or absolute (height above sea level).[4]
Appearance and rendering are governed by the <Style> element, which can be defined inline within a <Placemark> or shared via <Style> within a <Document> using the <styleUrl> reference.[4] Key sub-elements of <Style> include <IconStyle> for point icons and colors (using ABGR hexadecimal values, e.g., ffff0000 for opaque blue), <LineStyle> for line width and color, and <PolyStyle> for polygon fill and outline properties.[17] The schema requires that styles conform to the <StyleSelector> type, allowing selectors like <StyleMap> for conditional rendering based on normal or highlight states.[1]
The following example illustrates a basic KML structure with a <Placemark> containing a <Point> geometry, demonstrating the schema's coordinate and element constraints:
xml
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Sample Point</name>
<description>A simple geographic point.</description>
<Point>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>-122.371,37.816,0</coordinates>
</Point>
</Placemark>
</kml>
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Sample Point</name>
<description>A simple geographic point.</description>
<Point>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>-122.371,37.816,0</coordinates>
</Point>
</Placemark>
</kml>
This snippet validates against the ogckml23.xsd schema, with the coordinate specifying a location near San Francisco clamped to the ground surface.[4]
Document Organization
KML documents are structured as XML files with a hierarchical organization that enables the creation of complex geographic visualizations. The root element is <kml>, which encapsulates all content and declares the core namespace (xmlns="http://www.opengis.net/kml/2.2") along with optional extensions such as the Google namespace (xmlns:gx="http://www.google.com/kml/ext/2.2").[18][4] Within this root, the <Document> element serves as a primary container for organizing collections of features, styles, and schemas, allowing for shared definitions across the file.[19] <Folder> elements provide further grouping and nesting capabilities, enabling hierarchical arrangements of related features to build logical structures like categorized maps or layered data sets.[20] Additionally, <NetworkLink> elements facilitate dynamic loading by referencing remote KML files via URLs, supporting modular and updatable content without embedding everything in a single document.[21][22]
The feature hierarchy in KML builds upon this foundation, with core features like <Placemark>—which represent points, lines, or polygons—often nested within <Folder> or <Document> elements to create organized, reusable assemblies.[23] This nesting supports complex documents by allowing features to inherit styles and visibility settings from parent containers. For imagery, <GroundOverlay> elements drape raster images onto the terrain or ground plane, defined by bounding boxes, while <PhotoOverlay> elements position photos relative to the viewpoint with additional shape and rotation controls, both integrable into the hierarchy for enhanced visual layers.[24][25][26]
KML also supports interactive elements through the <Tour> feature (kml:Tour), a core element in KML 2.3 that defines guided animations and narratives. This element contains a <Playlist> that sequences actions such as <gx:FlyTo>, which smoothly transitions the view to specified coordinates over a duration, and <gx:Wait>, which introduces pauses between steps, all nested within the document hierarchy for seamless integration into broader feature sets.[27]
Files are saved with the .kml extension for plain-text XML or as .kmz for compressed ZIP archives that bundle the KML with supporting assets like images and models, preserving the hierarchical structure during distribution.[28] Namespace declarations, particularly the gx: prefix for extensions like tours, ensure compatibility while allowing proprietary enhancements without conflicting with the core OGC schema.[29]
Geodetic Reference Systems
Keyhole Markup Language (KML) employs the World Geodetic System 1984 (WGS 84) as its default coordinate reference system, specifically utilizing a 3D geocentric framework defined by the OGC URN http://www.opengis.net/def/crs/EPSG/0/4978, which corresponds to EPSG:4978 for geospatial positioning.[18] This system specifies longitude and latitude in decimal degrees, with longitude ranging from -180 to 180 degrees (positive eastward from the Prime Meridian) and latitude from -90 to 90 degrees (positive northward from the Equator).[18] Altitude is measured in meters, interpreted relative to the WGS 84 EGM96 geoid as the vertical datum, enabling accurate 3D representations of geographic features.[18]
Coordinates in KML are encoded as space-separated tuples within the <coordinates> element, following the order longitude, latitude, and optional altitude (e.g., -122.207881 37.371915 156.0).[18] For geometries such as points, linestrings, and polygons, multiple tuples form arrays separated by spaces, with no commas between values within a tuple and a single space between tuples (e.g., -122.207881 37.371915 0 -122.207639 37.792136 0).[18] The <Location> element, used in features like placemarks and models, similarly structures coordinates as separate <longitude>, <latitude>, and optional <altitude> child elements, each as double-precision floating-point values.[18] Interpolation between coordinate tuples in 3D geometries, such as linestrings, occurs along straight-line segments in the WGS 84 geocentric system to maintain geometric fidelity.[18]
Altitude interpretation is controlled by the <altitudeMode> element, which supports three values: clampToGround (default, positions features on the terrain surface without elevation), relativeToGround (altitude above the ground surface, suitable for relative heights like building elevations), and absolute (altitude above the sea level geoid, for fixed elevations independent of terrain).[18] This flexibility allows KML to represent both 2D overlays and 3D volumes accurately within the WGS 84 framework.
For 3D modeling, KML includes the <extrude> boolean element in geometries like <Polygon> and <LineString>, which, when set to true, extends features vertically from their coordinates to the ground level (using clampToGround semantics), enabling visualizations such as extruded buildings or walls.[18] The <Orientation> element, applied to <Model> features, defines 3D rotations with three attributes: <heading> (azimuth in degrees, 0 north, positive clockwise), <tilt> (pitch in degrees, 0 horizontal, positive forward), and <roll> (bank in degrees, 0 level, positive clockwise), allowing precise orientation of imported 3D models relative to the WGS 84 coordinates.[18]
KML does not support alternative projections or coordinate reference systems beyond WGS 84; all geographic data must be provided in this native geographic format, with any necessary reprojection handled by the client application during rendering.[18] This design simplifies data exchange but requires consuming software, such as Earth browsers, to perform transformations for display in projected views like plate carrée.[18]
Standardization
OGC Adoption Process
In May 2007, Google submitted Keyhole Markup Language (KML) to the Open Geospatial Consortium (OGC) for evolution through its consensus process, initially proposing it as an OGC Best Practice to facilitate broader adoption and interoperability in geographic visualization.[30] This submission followed Google's acquisition of Keyhole Inc. and the integration of its Earth Viewer software into Google Earth, aiming to standardize KML's XML-based format for encoding geographic features like placemarks, paths, and overlays.[1]
The standardization process began with approval of KML 2.1 as an OGC Best Practice during the April 2007 OGC Technical Committee meetings, marking the start of formal review by the OGC membership.[13] A dedicated Standards Working Group (SWG) for KML 2.2 was formed to manage development, incorporating feedback from the OGC Technical Committee, public requests for comments, and interoperability experiments involving GIS vendors to ensure compatibility with existing OGC standards.[1] These experiments focused on testing KML's integration with services like Web Map Service (WMS) and Web Feature Service (WFS), promoting seamless data exchange in earth browsers and mapping applications.[1]
KML 2.2.0 was approved as an official OGC implementation standard on April 14, 2008, after rigorous review and voting by the OGC membership, with full documentation and schema release completing the adoption by late 2008. This elevated KML to the OGC standards suite, enabling its use alongside protocols like WMS and WFS for enhanced geospatial interoperability.[13] Subsequent efforts included a draft of KML 2.3 in 2014, which underwent public comment and was approved as an OGC standard in October 2015, introducing features like XML Schema 1.1 support for better extensibility, though it saw limited widespread adoption compared to version 2.2.[18][14]
Versions and Extensions
Keyhole Markup Language (KML) has evolved through several versions since its inception, with early iterations developed by Google prior to formal standardization by the Open Geospatial Consortium (OGC). Version 2.0 was introduced in 2005 alongside the initial release of Google Earth, providing foundational support for geographic annotations and visualizations in 3D Earth browsers.[2] Version 2.1 followed in 2006, adding features such as level-of-detail (LOD) controls for efficient rendering of large datasets and enhanced altitude modes for 3D positioning.[31]
In 2008, the OGC adopted KML 2.2 as an official implementation standard, establishing it as the baseline for interoperability across geospatial applications and incorporating geometry elements derived from Geography Markup Language (GML) 2.1.2, including Point, LineString, LinearRing, and Polygon.[13] This version emphasized backward compatibility and became the reference for OGC-compliant tools. The subsequent KML 2.3, adopted by the OGC in October 2015, introduced enhancements such as support for XML Schema 1.1 in extensions, new time-based geometries like Track and MultiTrack for dynamic paths, and the Tour element for guided virtual navigation sequences.[14] Although a draft of 2.3 in 2014 proposed formalizing superoverlay mechanisms using ImagePyramid for hierarchical image tiling, this remains primarily a Google implementation rather than a core OGC addition.[18]
Google has extended KML beyond the OGC core through the gx namespace (http://www.google.com/kml/ext/2.2), enabling advanced features not included in standard specifications. Notable gx elements include gx:Tour for creating interactive playlists of fly-to animations and waits, gx:TimeSpan enhancements for time-specific views in abstract elements like Camera and LookAt, and gx:balloonVisibility within to dynamically control information popup display.[4] These extensions, such as gx:FlyTo for smooth transitions and gx:duration for timing controls, are supported in Google Earth but may not be rendered in OGC-compliant software without specific handling.[32]
KML enforces backward compatibility across versions, requiring parsers to process documents based on the version attribute in the root element (e.g., version="2.2"), while ignoring unrecognized elements from later versions.[6] Tools must validate against the specified schema to ensure interoperability, with deprecated features like certain URL handling in 2.3 migrated from prior releases.[18]
As of November 2025, the OGC maintains KML 2.3 as the current standard, with 2.2 serving as a stable reference for legacy implementations, while Google Earth continues to support 2.3 features and gx extensions informally for enhanced functionality in its ecosystem.[1] No major revisions have been adopted since 2015, though ongoing work in OGC working groups explores harmonization with other standards like GML.[1]
Applications and Usage
Integration with Google Earth
Keyhole Markup Language (KML) serves as the native file format for Google Earth, enabling the visualization of geographic data across its desktop, web, and mobile versions since the application's public release in 2005.[33] Google Earth parses KML and KMZ files to render elements such as placemarks, ground overlays, and 3D tours, allowing users to annotate the globe with points of interest, paths, polygons, and immersive narratives.[6] This integration originated from Keyhole, Inc.'s technology, acquired by Google in 2004, and has made KML central to Google Earth's functionality for displaying static and dynamic geospatial content.[34]
Rendering in Google Earth supports advanced KML features that enhance interactivity and realism. Dynamic styling allows for shared styles across elements, with options for highlighted icons, color-coded lines, and opacity adjustments to emphasize data layers.[6] Photo overlays, implemented via ground overlays and PhotoOverlay elements, drape images directly onto the terrain, creating realistic billboards or expansive scenic views that align with the Earth's curvature and elevation.[35] Network links enable live data integration, such as real-time weather updates or traffic feeds, by periodically refreshing external KML sources through view-based queries or CGI scripting, ensuring content remains current without manual intervention.[6][36]
Google Earth provides built-in tools for importing, creating, and exporting KML files, streamlining workflows for users. Files can be imported directly into projects or opened as local KML, supporting placemarks, paths, polygons, and simple network links, while complex features may require the desktop version for full compatibility.[37] Editing occurs through the interface, where users add and modify elements, then export as KML or compressed KMZ for sharing.[6] Integration with Google My Maps extends this to web-based creation, allowing KML imports for lines, shapes, and places, which can then be viewed or further edited in Google Earth.[38]
Post-2020 developments have emphasized cloud-based enhancements for KML handling in Google Earth. Projects now store KML data in Google Drive, enabling automatic syncing across desktop, web, and mobile devices for collaborative access and real-time updates.[39] This shift supports importing KML from Drive directly into cloud projects, preserving features like image overlays and tours while facilitating seamless multi-device workflows.[37]
Support in Other GIS Software
Keyhole Markup Language (KML) has seen widespread adoption in third-party Geographic Information System (GIS) software due to its standardization by the Open Geospatial Consortium (OGC), enabling interoperability across various platforms. Esri's ArcGIS, for instance, has supported KML import and export since version 9.2 released in 2007, leveraging Safe Software's Feature Manipulation Engine (FME) for handling KML files in geoprocessing workflows.[40] Similarly, the open-source QGIS provides comprehensive KML support through dedicated plugins such as KML Tools, which facilitate fast import, export, and conversion of KML/KMZ files while preserving attributes like description fields and ground overlays.[41]
In web-based GIS applications, KML rendering is enabled by JavaScript libraries that extend browser capabilities for geospatial visualization. CesiumJS, an open-source library for 3D globes and maps, includes a KmlDataSource module that supports major KML elements such as placemarks, polylines, polygons, and text, though coverage of the full OGC standard and Google extensions remains incomplete.[42] Leaflet, a lightweight library for interactive 2D maps, achieves KML compatibility via plugins like leaflet-kml and leaflet-omnivore, allowing users to overlay KML data on web maps with support for points, lines, and polygons.[43] For 3D applications, NASA's WorldWind platform offers robust KML parsing and rendering through its OGC KML package, enabling the import of KML/KMZ files as layers with tree-based navigation of features.[44]
Despite its broad compatibility, KML adoption in open-source GIS tools often encounters limitations, particularly with proprietary extensions and complex features like 3D models or time-based animations, which may not render fully in environments such as CesiumJS or QGIS plugins.[42] To address these gaps, conversion tools like the Geospatial Data Abstraction Library (GDAL) provide essential utilities, including the ogr2ogr command for transforming KML files to shapefiles while retaining geometry and attributes, facilitating integration with other GIS formats.[45]
As of 2025, KML continues to gain traction in specialized domains beyond general GIS, including urban planning software where Esri CityEngine supports direct import of KML/KMZ for points, lines, and polygons to aid in 3D city modeling and procedural design.[46] In IoT mapping applications, KML's structured format enables real-time feeds through dynamic network links and conversions, integrating geospatial data from sensors into platforms like ArcGIS for live visualization in sectors such as disaster response and environmental monitoring.[47] The August 2025 update to ArcGIS Earth further enhanced KML support with multi-geometry editing tools, such as combine and split, for improved handling of complex features.[48]