Reference Guide

Atom

KML 2.2 supports new elements for including data about the author and related website in your KML file. This information is displayed in geo search results, both in Earth browsers such as Google Earth, and in other applications such as Google Maps. The ascription elements used in KML are as follows:

atom:author element - parent element for atom:name atom:name element - the name of the author atom:link element - contains the href attribute href attribute - URL of the web page containing the KML/KMZ file

These elements are defined in the Atom Syndication Format. The complete specification is found at http://atompub.org.

This library only implements a subset of Atom that is useful with KML

class fastkml.atom.Author(ns=None, name=None, uri=None, email=None)

Names one author of the feed/entry. A feed/entry may have multiple authors.

class fastkml.atom.Contributor(ns=None, name=None, uri=None, email=None)

Names one contributor to the feed/entry. A feed/entry may have multiple contributor elements.

Identifies a related Web page. The type of relation is defined by the rel attribute. A feed is limited to one alternate per type and hreflang. <link> is patterned after html’s link element. It has one required attribute, href, and five optional attributes: rel, type, hreflang, title, and length.

to_string(prettyprint=True)

Return the ATOM Object as serialized xml

fastkml.atom.check_email()

match(string[, pos[, endpos]]) –> match object or None. Matches zero or more characters at the beginning of the string

Base

Abstract base classes

Config

Frequently used constants and configuration options

Geometry

Import the geometries from shapely if it is installed or otherwise from Pygeoif

class fastkml.geometry.Geometry(ns=None, id=None, geometry=None, extrude=False, tessellate=False, altitude_mode=None)

GX

With the launch of Google Earth 5.0, Google has provided extensions to KML to support a number of new features. These extensions use the gx prefix and the following namespace URI:

xmlns:gx="http://www.google.com/kml/ext/2.2"

This namespace URI must be added to the <kml> element in any KML file using gx-prefixed elements:

<kml
    xmlns="http://www.opengis.net/kml/2.2"
    xmlns:gx="http://www.google.com/kml/ext/2.2"
>

Extensions to KML may not be supported in all geo-browsers. If your browser doesn’t support particular extensions, the data in those extensions should be silently ignored, and the rest of the KML file should load without errors.

Elements that currently use the gx prefix are:

  • gx:altitudeMode
  • gx:altitudeOffset
  • gx:angles
  • gx:AnimatedUpdate
  • gx:balloonVisibility
  • gx:coord
  • gx:delayedStart
  • gx:drawOrder
  • gx:duration
  • gx:FlyTo
  • gx:flyToMode
  • gx:h
  • gx:horizFov
  • gx:interpolate
  • gx:labelVisibility
  • gx:LatLonQuad
  • gx:MultiTrack
  • gx:vieweroptions
  • gx:outerColor
  • gx:outerWidth
  • gx:physicalWidth
  • gx:Playlist
  • gx:playMode
  • gx:SoundCue
  • gx:TimeSpan
  • gx:TimeStamp
  • gx:Tour
  • gx:TourControl
  • gx:TourPrimitive
  • gx:Track
  • gx:ViewerOptions
  • gx:w
  • gx:Wait
  • gx:x
  • gx:y

The complete XML schema for elements in this extension namespace is located at http://developers.google.com/kml/schema/kml22gx.xsd.

KML

KML is an open standard officially named the OpenGIS KML Encoding Standard (OGC KML). It is maintained by the Open Geospatial Consortium, Inc. (OGC). The complete specification for OGC KML can be found at http://www.opengeospatial.org/standards/kml/.

The complete XML schema for KML is located at http://schemas.opengis.net/kml/.

class fastkml.kml.Data(ns=None, name=None, value=None, display_name=None)

Represents an untyped name/value pair with optional display name.

class fastkml.kml.Document(ns=None, id=None, name=None, description=None, styles=None, styleUrl=None)

A Document is a container for features and styles. This element is required if your KML file uses shared styles or schemata for typed extended data

class fastkml.kml.ExtendedData(ns=None, elements=None)

Represents a list of untyped name/value pairs. See docs:

-> ‘Adding Untyped Name/Value Pairs’
https://developers.google.com/kml/documentation/extendeddata
class fastkml.kml.Folder(ns=None, id=None, name=None, description=None, styles=None, styleUrl=None)

A Folder is used to arrange other Features hierarchically (Folders, Placemarks, #NetworkLinks, or #Overlays).

class fastkml.kml.GroundOverlay(ns=None, id=None, name=None, description=None, styles=None, styleUrl=None)

This element draws an image overlay draped onto the terrain. The <href> child of <Icon> specifies the image to be used as the overlay. This file can be either on a local file system or on a web server. If this element is omitted or contains no <href>, a rectangle is drawn using the color and LatLonBox bounds defined by the ground overlay.

class fastkml.kml.KML(ns=None)

represents a KML File

append(kmlobj)

append a feature

features()

iterate over features

from_string(xml_string)

create a KML object from a xml string

to_string(prettyprint=False)

Return the KML Object as serialized xml

class fastkml.kml.Placemark(ns=None, id=None, name=None, description=None, styles=None, styleUrl=None, extended_data=None)

A Placemark is a Feature with associated Geometry. In Google Earth, a Placemark appears as a list item in the Places panel. A Placemark with a Point has an icon associated with it that marks a point on the Earth in the 3D viewer.

class fastkml.kml.Schema(ns=None, id=None, name=None, fields=None)

Specifies a custom KML schema that is used to add custom data to KML Features. The “id” attribute is required and must be unique within the KML file. <Schema> is always a child of <Document>.

append(type, name, displayName=None)

append a field. The declaration of the custom field, must specify both the type and the name of this field. If either the type or the name is omitted, the field is ignored.

The type can be one of the following:
string int uint short ushort float double bool

<displayName> The name, if any, to be used when the field name is displayed to the Google Earth user. Use the [CDATA] element to escape standard HTML markup.

class fastkml.kml.SchemaData(ns=None, schema_url=None, data=None)

<SchemaData schemaUrl=”anyURI”> This element is used in conjunction with <Schema> to add typed custom data to a KML Feature. The Schema element (identified by the schemaUrl attribute) declares the custom data type. The actual data objects (“instances” of the custom data) are defined using the SchemaData element. The <schemaURL> can be a full URL, a reference to a Schema ID defined in an external KML file, or a reference to a Schema ID defined in the same KML file.

class fastkml.kml.TimeSpan(ns=None, id=None, begin=None, begin_res=None, end=None, end_res=None)

Represents an extent in time bounded by begin and end dateTimes.

class fastkml.kml.TimeStamp(ns=None, id=None, timestamp=None, resolution=None)

Represents a single moment in time.

class fastkml.kml.UntypedExtendedData(ns=None, elements=None)
class fastkml.kml.UntypedExtendedDataElement(ns=None, name=None, value=None, display_name=None)

Styles

Once you’ve created features within Google Earth and examined the KML code Google Earth generates, you’ll notice how styles are an important part of how your data is displayed.

class fastkml.styles.BalloonStyle(ns=None, id=None, bgColor=None, textColor=None, text=None, displayMode=None)

Specifies how the description balloon for placemarks is drawn. The <bgColor>, if specified, is used as the background color of the balloon.

class fastkml.styles.IconStyle(ns=None, id=None, color=None, colorMode=None, scale=1.0, heading=None, icon_href=None)

Specifies how icons for point Placemarks are drawn

class fastkml.styles.LabelStyle(ns=None, id=None, color=None, colorMode=None, scale=1.0)

Specifies how the <name> of a Feature is drawn in the 3D viewer

class fastkml.styles.LineStyle(ns=None, id=None, color=None, colorMode=None, width=1)

Specifies the drawing style (color, color mode, and line width) for all line geometry. Line geometry includes the outlines of outlined polygons and the extruded “tether” of Placemark icons (if extrusion is enabled).

class fastkml.styles.PolyStyle(ns=None, id=None, color=None, colorMode=None, fill=1, outline=1)

Specifies the drawing style for all polygons, including polygon extrusions (which look like the walls of buildings) and line extrusions (which look like solid fences).

class fastkml.styles.Style(ns=None, id=None, styles=None)

A Style defines an addressable style group that can be referenced by StyleMaps and Features. Styles affect how Geometry is presented in the 3D viewer and how Features appear in the Places panel of the List view. Shared styles are collected in a <Document> and must have an id defined for them so that they can be referenced by the individual Features that use them.

class fastkml.styles.StyleMap(ns=None, id=None, normal=None, highlight=None)

A <StyleMap> maps between two different Styles. Typically a <StyleMap> element is used to provide separate normal and highlighted styles for a placemark, so that the highlighted version appears when the user mouses over the icon in Google Earth.

class fastkml.styles.StyleUrl(ns=None, id=None, url=None)

URL of a <Style> or <StyleMap> defined in a Document. If the style is in the same file, use a # reference. If the style is defined in an external file, use a full URL along with # referencing.