kml - Imports KML data files.

class upoints.kml.Placemark(latitude, longitude, altitude=None, name=None, description=None)[source]

Bases: upoints.trigpoints.Trigpoint

Class for representing a Placemark element from KML data files.

New in version 0.6.0.

Initialise a new Placemark object.

  • latitude (float) – Placemarks’s latitude
  • longitude (float) – Placemark’s longitude
  • altitude (float) – Placemark’s altitude
  • name (str) – Name for placemark
  • description (str) – Placemark’s description

Generate a KML Placemark element subtree.

Returns:KML Placemark element
Return type:etree.Element
class upoints.kml.Placemarks(kml_file=None)[source]

Bases: upoints.point.KeyedPoints

Class for representing a group of Placemark objects.

New in version 0.6.0.

Initialise a new Placemarks object.


Generate KML element tree from Placemarks.

Returns:KML element tree depicting Placemarks
Return type:etree.ElementTree

Import KML data files.

import_locations() returns a dictionary with keys containing the section title, and values consisting of Placemark objects.

It expects data files in KML format, as specified in KML Reference, which is XML such as:

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="">
        <Placemark id="Home">
        <Placemark id="Cambridge">

The reader uses the ElementTree module, so should be very fast when importing data. The above file processed by import_locations() will return the following dict object:

{"Home": Placemark(52.015, -0.221, 60),
 "Cambridge": Placemark(52.167, 0.390, None)}
Parameters:kml_file (iter) – KML data to read
Returns:Named locations with optional comments
Return type:dict