]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/KML.py
4b6d12f3fdcfcb47eace8548ea3566b1d7e7b999
2 Utility classes for working with the Keyhole Markup Language (KML).
8 class KmlObject(object):
10 The base class of all KML elements, according to the reference:
12 http://code.google.com/apis/kml/documentation/kmlreference.html
14 Every other class in this module should derive from
15 KmlObject. This class provides a default constructor which creates
16 some necessary attributes, and default implementations of to_kml()
19 The to_kml() methods of our subclasses will, in general, generate
20 an opening tag, render themselves (whatever that means), and then
21 generate a closing tag. A call to render() generally returns the
22 element's text, and renders its children recursively.
28 def __init__(self
, initial_text
=''):
30 self
.text
= initial_text
41 for c
in self
.children
:
44 kml
+= self
.CLOSE_TAG
+ "\n"
51 self
.render_to_stdout()
55 def render_to_stdout(self
):
56 if not (len(self
.text
) == 0):
59 for c
in self
.children
:
64 class Color(KmlObject
):
67 CLOSE_TAG
= '</color>'
70 class Document(KmlObject
):
72 OPEN_TAG
= """<?xml version=\"1.0\" encoding=\"UTF-8\"?>
73 <kml xmlns=\"http://www.opengis.net/kml/2.2\">
76 CLOSE_TAG
= """</Document>
79 def __init__(self
, initial_text
=''):
80 super(Document
, self
).__init
__(initial_text
)
90 for c
in self
.children
:
96 def render_to_stdout(self
):
100 for c
in self
.children
:
105 class Description(KmlObject
):
107 OPEN_TAG
= '<description>'
108 CLOSE_TAG
= '</description>'
112 class Name(KmlObject
):
115 CLOSE_TAG
= '</name>'
119 class Placemark(KmlObject
):
121 OPEN_TAG
= '<Placemark>'
122 CLOSE_TAG
= '</Placemark>'
126 class PolyStyle(KmlObject
):
128 OPEN_TAG
= '<PolyStyle>'
129 CLOSE_TAG
= '</PolyStyle>'
133 class Style(KmlObject
):
135 OPEN_TAG
= "<Style id=\"%s\">"
136 CLOSE_TAG
= '</Style>'
138 def __init__(self
, initial_text
='', initial_id
=''):
139 super(Style
, self
).__init
__(initial_text
)
145 kml
+= (self
.OPEN_TAG
% self
.id + "\n")
147 kml
+= self
.CLOSE_TAG
+ "\n"
153 print (self
.OPEN_TAG
% self
.id)
154 self
.render_to_stdout()
159 class StyleUrl(KmlObject
):
161 OPEN_TAG
= '<styleUrl>'
162 CLOSE_TAG
= '</styleUrl>'
166 class RawText(KmlObject
):