What Is KML and How Does It Work with XML?
Keyhole Markup Language (KML) is an XML-based file format used to display geographic data in two-dimensional maps and three-dimensional Earth browsers. This article explains what KML is, how it leverages the structured syntax of XML to store geographic annotations and spatial features, and the primary components used to render interactive visualizations such as placemarks, paths, polygons, and 3D overlays.
Understanding KML
KML was originally developed by Keyhole, Inc., a company acquired by Google in 2004. It became the default data format for Google Earth and was later adopted as an open international standard by the Open Geospatial Consortium (OGC) in 2008.
At its core, KML enables users to pinpoint locations, add descriptions, overlay imagery, draw geometric shapes, and define dynamic camera angles. It acts as a bridge between raw geographic coordinates and rich, visual spatial presentations.
How KML Leverages XML
Extensible Markup Language (XML) provides the foundational syntax for KML. XML uses a tag-based, human-readable, and machine-parsable nested hierarchy. KML adopts this standard by defining a specific schema—a defined set of XML tags and attributes—tailored specifically to geographic data.
Because KML is standard XML: * It follows standard XML rules (e.g., case sensitivity, closed tags, proper nesting). * It uses namespaces to define the exact version and schema rules being used. * It can be created, edited, and parsed using standard text editors and XML parsing libraries.
Key KML Elements for Geographic Annotation
KML translates geographic concepts into specific XML tags. The most common building blocks include:
1. Placemarks and Coordinates
The <Placemark> tag is the most fundamental
feature in KML, used to mark a specific location on the globe. It pairs
geographic coordinates with descriptive data.
<coordinates>: Contains longitude, latitude, and optional altitude values (in that exact order, separated by commas).<name>: The title of the location.<description>: Information displayed in a pop-up balloon when the placemark is clicked, supporting plain text or HTML.
2. Geometries (Paths and Polygons)
Beyond single points, KML represents spatial areas and routes through
geometric tags: * <Point>: Defines a single
coordinate location. * <LineString>: Connects
multiple coordinates to create paths, roads, or flight tracks. *
<Polygon>: Encloses a set of coordinates to represent
boundaries, parcels, or regions, with options to extrude the shape into
3D space.
3. Visual Styling
KML allows precise control over how elements look on a map using
<Style> tags: * <IconStyle>:
Changes the marker icon, size, and color. *
<LineStyle>: Controls the color, transparency, and
width of paths. * <PolyStyle>: Defines fill colors
and boundary properties for polygons.
4. Overlays and Perspectives
KML extends beyond static shapes by supporting complex spatial
overlays and viewing perspectives: * <GroundOverlay>:
Drapes raster images (such as weather maps or historical blueprints)
directly onto the terrain. * <LookAt> and
<Camera>: Specify exact virtual camera positioning,
including heading, tilt, altitude, and roll, allowing creators to script
guided geographic tours.
KML vs. KMZ
A KMZ file is simply a compressed KML file packaged as a standard ZIP
archive. KMZ bundles the main KML document (doc.kml)
alongside any referenced local assets—such as custom icons, images for
ground overlays, or 3D models (COLLADA files)—into a single, easily
shareable file.
Common Applications of KML
- Geographic Visualization: Sharing points of interest, hiking routes, or flight paths in tools like Google Earth, Google Maps, and ArcGIS.
- Urban Planning and Architecture: Visualizing proposed building designs and zoning boundaries within real-world 3D landscapes.
- Environmental and Scientific Research: Mapping field data, tracking wildlife movements, and overlaying satellite imagery to monitor environmental changes over time.