]> gitweb.michael.orlitzky.com - dead/census-tools.git/blobdiff - src/KML.py
Added a Coordinates class, and updated the LineString class to refer to Coordinates...
[dead/census-tools.git] / src / KML.py
index 1f42898d6d4f48070381e93da2113a2b6af422a2..9b589ad582c0ac4f11c16a775222716bf7fa1d2f 100644 (file)
@@ -32,17 +32,17 @@ class KmlObject(object):
 
         
     def to_kml(self):
-        return self.render()
+        kml = self.OPEN_TAG
+        kml += self.render()
+        kml += self.CLOSE_TAG + "\n"
+        return kml
 
 
     def render(self):
-        kml = self.OPEN_TAG
-        kml += escape(self.text)
+        kml = escape(self.text)
 
         for c in self.children:
             kml += c.to_kml()
-
-        kml += self.CLOSE_TAG + "\n"
         
         return kml
 
@@ -75,7 +75,7 @@ class Document(KmlObject):
 <Document>"""
 
     CLOSE_TAG = """</Document>
-    </kml>"""
+</kml>"""
     
     def __init__(self, initial_text=''):
         super(Document, self).__init__(initial_text)
@@ -110,6 +110,12 @@ class Description(KmlObject):
 
 
 
+class Coordinates(KmlObject):
+
+    OPEN_TAG = '<coordinates>'
+    CLOSE_TAG = '</coordinates>'
+
+
 class LineString(KmlObject):
 
     OPEN_TAG = '<LineString>'
@@ -140,9 +146,9 @@ class LineString(KmlObject):
         coords = []
 
         for ls in linestrings:
-            c_tag_start = ls.find('<coordinates>')
-            c_start = c_tag_start + len('<coordinates>')
-            c_end = ls.find('</coordinates>')
+            c_tag_start = ls.find(Coordinates.OPEN_TAG)
+            c_start = c_tag_start + len(Coordinates.OPEN_TAG)
+            c_end = ls.find(Coordinates.CLOSE_TAG)
             c = ls[ c_start : c_end ]
             coords.append(c)