Trees | Indices | Help |
|
---|
|
object --+ | dict --+ | point.KeyedPoints --+ | Placemarks
Since: 0.6.0
|
|||
new empty dictionary |
|
||
dict
|
|
||
ET.ElementTree |
|
||
Inherited from Inherited from Inherited from |
|
|||
Inherited from |
|
|
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 Python's ElementTree
module, so should be very fast when importing data. The above file
processed by import_locations() will return the following {"Home": Placemark(52.015, -0.221, 60), "Cambridge": Placemark(52.167, 0.390, None)} >>> locations = Placemarks(open("kml")) >>> for value in sorted(locations.values(), ... key=lambda x: x.name.lower()): ... print(value) Cambridge (52°10'01"N, 000°23'24"E) Home (52°00'54"N, 000°13'15"W alt 60m) The
|
Generate KML element tree from Placemarks >>> from sys import stdout >>> locations = Placemarks(open("kml")) >>> xml = locations.export_kml_file() >>> xml.write(stdout) <ns0:kml xmlns:ns0="http://earth.google.com/kml/2.2"><ns0:Document><ns0:Placemark id="Home"><ns0:name>Home</ns0:name><ns0:Point><ns0:coordinates>-0.221,52.015,60</ns0:coordinates></ns0:Point></ns0:Placemark><ns0:Placemark id="Cambridge"><ns0:name>Cambridge</ns0:name><ns0:Point><ns0:coordinates>0.39,52.167</ns0:coordinates></ns0:Point></ns0:Placemark></ns0:Document></ns0:kml> >>> xml = locations.export_kml_file("2.0") >>> xml.write(stdout) <ns0:kml xmlns:ns0="http://earth.google.com/kml/2.0"><ns0:Document><ns0:Placemark id="Home"><ns0:name>Home</ns0:name><ns0:Point><ns0:coordinates>-0.221,52.015,60</ns0:coordinates></ns0:Point></ns0:Placemark><ns0:Placemark id="Cambridge"><ns0:name>Cambridge</ns0:name><ns0:Point><ns0:coordinates>0.39,52.167</ns0:coordinates></ns0:Point></ns0:Placemark></ns0:Document></ns0:kml>
|
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue May 20 12:41:21 2008 | http://epydoc.sourceforge.net |