Worked on formatting of output from create_wrmap.
[philipp/winterrodeln/wrpylib.git] / wrpylib / wrmwmarkup.py
index 1ed237f3abb0b3b4ab25517ee10e76f874010a69..d131402f3bee9ddd57f6bf7887294cde726099c7 100644 (file)
@@ -515,19 +515,29 @@ def create_wrmap_coordinates(coords):
 def create_wrmap(geojson):
     """Creates a <wrmap> wikitext from geojson (as python types)."""
     wrmap_xml = xml.etree.ElementTree.Element('wrmap')
+    wrmap_xml.text = '\n\n'
     for k, v in geojson['properties'].iteritems():
         wrmap_xml.attrib[k] = str(v)
 
     assert geojson['type'] == 'FeatureCollection'
     json_features = geojson['features']
+    last_json_feature = None
     for json_feature in json_features:
         feature_xml = xml.etree.ElementTree.SubElement(wrmap_xml, json_feature['properties']['type'])
         geo = json_feature['geometry']
         if geo['type'] == 'Point':
             feature_xml.text = create_wrmap_coordinates([geo['coordinates']])
+            if last_json_feature is not None:
+                last_json_feature.tail = '\n'
         else:
-            feature_xml.text = create_wrmap_coordinates(geo['coordinates'])
+            if last_json_feature is not None:
+                last_json_feature.tail = '\n\n'
+            feature_xml.text = '\n' + create_wrmap_coordinates(geo['coordinates']) + '\n'
+        last_json_feature = feature_xml
         feature_xml.attrib = json_feature['properties']
 
+    print last_json_feature.tag
+    if last_json_feature is not None:
+        last_json_feature.tail = '\n\n'
     return xml.etree.ElementTree.tostring(wrmap_xml)