TMewesGalileo commited on
Commit
e49d6a7
·
verified ·
1 Parent(s): 121b9f9

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +44 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from xml.etree.ElementTree import Element, SubElement, tostring
3
+ import xml.dom.minidom as minidom
4
+ import gradio as gr
5
+
6
+ def convert_json_to_kml(json_file):
7
+ data = json.load(json_file)
8
+
9
+ kml = Element('kml', xmlns="http://www.opengis.net/kml/2.2")
10
+ document = SubElement(kml, 'Document')
11
+
12
+ for i, track in enumerate(data):
13
+ placemark = SubElement(document, 'Placemark')
14
+ name = SubElement(placemark, 'name')
15
+ name.text = f"Track {i + 1}"
16
+
17
+ linestring = SubElement(placemark, 'LineString')
18
+ tessellate = SubElement(linestring, 'tessellate')
19
+ tessellate.text = '1'
20
+
21
+ coordinates = SubElement(linestring, 'coordinates')
22
+ coord_text = "\n".join(
23
+ [f"{point['longitude']},{point['latitude']},0" for point in track]
24
+ )
25
+ coordinates.text = coord_text
26
+
27
+ kml_str = minidom.parseString(tostring(kml)).toprettyxml(indent=" ")
28
+
29
+ kml_path = "/tmp/converted_track.kml"
30
+ with open(kml_path, "w") as f:
31
+ f.write(kml_str)
32
+
33
+ return kml_path
34
+
35
+ iface = gr.Interface(
36
+ fn=convert_json_to_kml,
37
+ inputs=gr.File(label="Upload JSON File"),
38
+ outputs=gr.File(label="Download KML File"),
39
+ title="JSON to KML Converter",
40
+ description="Upload a JSON file with latitude/longitude tracks to generate a KML file."
41
+ )
42
+
43
+ if __name__ == "__main__":
44
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio