X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;ds=inline;f=src%2FKML.py;h=4b6d12f3fdcfcb47eace8548ea3566b1d7e7b999;hb=717a5d47751909c5b2e0d9e984c340cb2e50be82;hp=890021da4167d13b0e9f7f56ae984a3c76f50f51;hpb=18b00503e26e51db44a6b3d9b279162f8278b868;p=dead%2Fcensus-tools.git
diff --git a/src/KML.py b/src/KML.py
index 890021d..4b6d12f 100644
--- a/src/KML.py
+++ b/src/KML.py
@@ -21,6 +21,9 @@ class KmlObject(object):
generate a closing tag. A call to render() generally returns the
element's text, and renders its children recursively.
"""
+
+ OPEN_TAG = ''
+ CLOSE_TAG = ''
def __init__(self, initial_text=''):
self.children = []
@@ -32,45 +35,52 @@ class KmlObject(object):
def render(self):
- kml = self.text
+ kml = self.OPEN_TAG
+ kml += self.text
for c in self.children:
kml += c.to_kml()
+ kml += self.CLOSE_TAG + "\n"
+
return kml
+ def print_kml(self):
+ print self.OPEN_TAG
+ self.render_to_stdout()
+ print self.CLOSE_TAG
+
+
+ def render_to_stdout(self):
+ if not (len(self.text) == 0):
+ print self.text
+
+ for c in self.children:
+ c.print_kml()
+
+
class Color(KmlObject):
- def to_kml(self):
- kml = ''
- kml += self.render()
- kml += "\n"
- return kml
+ OPEN_TAG = ''
+ CLOSE_TAG = ''
-
class Document(KmlObject):
+
+ OPEN_TAG = """
+
+"""
+
+ CLOSE_TAG = """
+ """
def __init__(self, initial_text=''):
super(Document, self).__init__(initial_text)
self.styles = []
- def to_kml(self):
- kml = "\n"
- kml += "\n"
- kml += "\n"
-
- kml += self.render()
-
- kml += "\n"
- kml += "\n"
-
- return kml
-
-
def render(self):
kml = ''
@@ -83,78 +93,75 @@ class Document(KmlObject):
return kml
+ def render_to_stdout(self):
+ for s in self.styles:
+ s.print_kml()
+
+ for c in self.children:
+ c.print_kml()
+
+
class Description(KmlObject):
- def to_kml(self):
- kml = ''
- kml += self.render()
- kml += "\n"
- return kml
-
+ OPEN_TAG = ''
+ CLOSE_TAG = ''
+
class Name(KmlObject):
- def to_kml(self):
- kml = ''
- kml += self.render()
- kml += "\n"
- return kml
-
+ OPEN_TAG = ''
+ CLOSE_TAG = ''
+
class Placemark(KmlObject):
-
- def to_kml(self):
- kml = "\n"
- kml += self.render()
- kml += "\n"
- return kml
-
-
+
+ OPEN_TAG = ''
+ CLOSE_TAG = ''
+
+
class PolyStyle(KmlObject):
-
- def to_kml(self):
- kml = "\n"
- kml += self.render()
- kml += "\n"
- return kml
-
+
+ OPEN_TAG = ''
+ CLOSE_TAG = ''
+
class Style(KmlObject):
-
- def __init__(self, initial_text='', initial_id=None):
+
+ OPEN_TAG = "'
+
+ def __init__(self, initial_text='', initial_id=''):
super(Style, self).__init__(initial_text)
self.id = initial_id
def to_kml(self):
kml = ''
-
- if (self.id == None):
- kml += "\n"
+ kml += self.CLOSE_TAG + "\n"
return kml
+ def print_kml(self):
+ print (self.OPEN_TAG % self.id)
+ self.render_to_stdout()
+ print self.CLOSE_TAG
-class StyleUrl(KmlObject):
-
- def to_kml(self):
- kml = ''
- kml += self.render()
- kml += "\n"
- return kml
+
+class StyleUrl(KmlObject):
+
+ OPEN_TAG = ''
+ CLOSE_TAG = ''
+
class RawText(KmlObject):
pass