Keytree 0.2.1
Keytree provides some utilities for manipulating KML using the ElementTree API. I've added factories for KML placemark and geometry elements, input being geojson or Shapely objects:
>>> 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.' ... )
Any object that provides the Python geo-feature interface will do. Next, you need a KML document as context for a new placemark:
>>> data = """ ... <kml xmlns="http://www.opengis.net/kml/2.2"> ... <Document> ... </Document> ... </kml> ... """ >>> from xml.etree import ElementTree >>> kml = ElementTree.fromstring(data)
Make a placemark element using the element factory:
>>> elem = keytree.element(kml, f) >>> import pprint >>> pprint.pprint((elem.tag, elem.text, list(elem))) ('{http://www.opengis.net/kml/2.2}Placemark', None, [<Element {http://www.opengis.net/kml/2.2}name at ...>, <Element {http://www.opengis.net/kml/2.2}Snippet at ...>, <Element {http://www.opengis.net/kml/2.2}description at ...>, <Element {http://www.opengis.net/kml/2.2}Point at ...>]) >>> pprint.pprint(list((e.tag, e.text, list(e)) for e in elem)) [('{http://www.opengis.net/kml/2.2}name', 'Feature 1', []), ('{http://www.opengis.net/kml/2.2}Snippet', 'The first feature', []), ('{http://www.opengis.net/kml/2.2}description', 'Blah, blah, blah.', []), ('{http://www.opengis.net/kml/2.2}Point', None, [<{http://www.opengis.net/kml/2.2}Element coordinates at ...>])]
This element could be appended to the Document element, or you could use the subelement factory:
More at http://pypi.python.org/pypi/keytree/.
Now, I'm trying to decide if something similar would be useful for Atom with GeoRSS.