kml

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.

Parameters:
  • 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
tokml()[source]

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.

export_kml_file()[source]

Generate KML element tree from Placemarks.

Returns:KML element tree depicting Placemarks
Return type:etree.ElementTree
import_locations(kml_file)[source]

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="http://earth.google.com/kml/2.1">
    <Document>
        <Placemark id="Home">
            <name>Home</name>
            <Point>
                <coordinates>-0.221,52.015,60</coordinates>
            </Point>
        </Placemark>
        <Placemark id="Cambridge">
            <name>Cambridge</name>
            <Point>
                <coordinates>0.390,52.167</coordinates>
            </Point>
        </Placemark>
    </Document>
</kml>

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