KML (.kml, .kmz)

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 and ExportImport and 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 Graphics 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 reference pages for full general information on Import and Export.
  • ImportString and ExportString support the KML format.


  • General Import elements:
  • "Elements"list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties, and settings
  • Data representation elements:
  • "Data"rule-based representation for each feature of a KML archive
    "Graphics"all layers combined into a single Graphics object
    "GraphicsList"list of graphics representing the layers of a KML archive
    "ImageOverlays"raster image overlays
  • Import by default uses the element for the KML format.
  • Import with element gives the combined graphics contents as vector and raster graphics.
  • Import["file", "Data"] returns an expression of the form . Individual layers are given as a list of rules representing the geometry as well as numerical and textual information associated with the features.
  • The 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.


ExamplesExamplesopen allclose all

Basic Examples (5)Basic Examples (5)

Import all layers from a KML file:

Click for copyable input

Import layers as a list:

Click for copyable input

Import the layer names:

Click for copyable input

Import city information:

Click for copyable input

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

Click for copyable input

Find the shortest path between the 40 largest German cities and export it to KML:

Click for copyable input
Click for copyable input
Click for copyable input
Click for copyable input
New in 8
New to Mathematica? Find your learning path »
Have a question? Ask support »