Keytree
2008-05-01T21:30:26Z | Comments: 2
Keytree (also known as pleiades.keytree in our repository) is a simple package of ElementTree helpers for parsing KML. I needed it, didn't see anything else like it out there, and put in a little extra work to make it more generally useful. If you're already using ElementTree and are curious, give it a try. It plays well with Shapely, of course:
>>> from xml.etree import ElementTree >>> tree = ElementTree.parse(open('archaic.kml', 'rb')) >>> kmlns = tree.getroot().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.wkt 'POINT (21.9725000000000001 32.8962999999999965)'
Keytree parses out points, line strings, and polygons, but not yet geometry collections. I'll make a real release of it after I get a chance to work on compatibility with lxml.
