This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!
Project Description

Keytree provides several functions for manipulating KML using the ElementTree API. Elements can be adapted to the Python geo interface and then used with packages like Shapely:

>>> data = """<?xml version="1.0" encoding="UTF-8"?>
... <kml xmlns="">
...   <Document>
...     <Placemark>
...       <name>point</name>
...       <description>Point test</description>
...       <Point>
...         <coordinates>
...           -122.364383,37.824664,0
...         </coordinates>
...       </Point>
...     </Placemark>
...   </Document>
... </kml>
... """
>>> from xml.etree import ElementTree
>>> tree = ElementTree.fromstring(data)
>>> kmlns = tree.tag.split('}')[0][1:]
>>> placemarks = tree.findall('*/{%s}Placemark' % kmlns)
>>> p0 = placemarks[0]
>>> import keytree
>>> f = keytree.feature(p0)
>>> from shapely.geometry import asShape
>>> shape = asShape(f.geometry)
>>> shape.buffer(1.5).exterior.length

Objects like those from geojson that provide the Python geo interface can also be converted to ElementTree API Elements:

>>> from geojson import Feature
>>> f = Feature('1',
...             geometry={
...                 'type': 'Point',
...                 'coordinates': (-122.364383, 37.824663999999999)
...                 },
...             title='Feature 1',
...             summary='The first feature',
...             content='Blah, blah, blah.'
...             )

A Shapely (or geojson) geometry could also be used in place of the dict:

>>> from shapely.geometry import Point
>>> f = Feature('1',
...             geometry=Point(-122.364383, 37.824664),
...             title='Feature 1',
...             summary='The first feature',
...             content='Blah, blah, blah.'
...             )

The first argument to the keytree.element function is an XML context, the created element will have the same namespace as that element:

>>> elem = keytree.element(tree, f)
>>> import pprint
>>> pprint.pprint((elem.tag, elem.text, list(elem)))
 [<Element {}name at ...>,
  <Element {}Snippet at ...>,
  <Element {}description at ...>,
  <Element {}Point at ...>])
>>> pprint.pprint(list((e.tag, e.text, list(e)) for e in elem))
[('{}name', 'Feature 1', []),
 ('{}Snippet', 'The first feature', []),
 ('{}description', 'Blah, blah, blah.', []),
  [<{}Element coordinates at ...>])]
Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
keytree-0.2.1.tar.gz (6.8 kB) Copy SHA256 Checksum SHA256 Source Apr 5, 2009

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting