KML (.kml, .kmz)

Background & Context

    • KML map data format.
    • Standard GIS file format.
    • Stores the geometry and data of cartographic map features.
    • KML is an acronym for Keyhole Markup Language.
    • Used by Google Earth.
    • Consists of multiple files combined in a file archive.
    • XML format.
    • Standard format of the Open Geospatial Consortium.

Import & Export

  • Import["file.kml"] imports a KML file and returns a combined rendering of all graphics layers.
  • Export["file.kml", expr] exports the data to KML.
  • Import["file.kml"] returns a GeoGraphics object.
  • Import["file.kml","elem"] imports the specified element from a KML file.
  • Import["file.kml",{{"elem1","elem2",}}] imports multiple elements.
  • Export["file.kml",{layer1,layer2,},{"KML","Data"}] exports expressions representing KML features to a file.
  • See the following reference pages for full general information:
  • Import, Exportimport from or export to a file
    CloudImport, CloudExportimport from or export to a cloud object
    ImportString, ExportStringimport from or export to a string
    ImportByteArray, ExportByteArrayimport from or export to a byte array

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements
  • Data representation elements:
  • "Data"rule-based representation for each feature of a KML archive
    "Graphics"all layers combined into a single GeoGraphics object
    "GraphicsList"list of graphics representing the layers of a KML archive
    "ImageOverlays"raster image overlays
  • Import by default uses the "Graphics" element for the KML format.
  • Import with element "Graphics" gives the combined graphics contents as vector and raster graphics.
  • Import["file","Data"] returns an expression of the form { layer1,layer2,} . Individual layers are given as a list of rules representing the geometry as well as numerical and textual information associated with the features.
  • The "Data" element supports the following features on Export:
  • "ExtendedData"extended data given as lists of rules
    "Geometry"list of Line, Point, and Polygon primitives
    "LabeledData"data given as a list of rules
    "LayerName"layer given as a string
    "NetworkLinks"list of strings representing links
    "Overlays"rules representing ground overlays
    "PlacemarkNames"names of placemarks given as strings
  • Meta-information elements:
  • "LayerNames"all layer names, given as a list of strings
    "LayerTypes"what graphics primitives comprise each layer
    "SpatialRange"range of geographic coordinates, typically given in decimal degrees
  • Geographic coordinates in KML files always refer to the WGS84 datum.

Options

Examples

open allclose all

Basic Examples  (5)

Import all layers from a KML file:

Import layers as a list:

Import the layer names:

Import city information:

Show a list of all import elements available for this file:

Applications  (1)

Find the shortest path between the 40 largest German cities:

Export the resulting tour: