Léo Bourrel commited on
Commit
1f03301
·
0 Parent(s):

feat: read KML

Browse files
Files changed (1) hide show
  1. src/read_kml.py +28 -0
src/read_kml.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import xml
2
+ import xml.dom
3
+ import xml.etree
4
+ import xml.etree.ElementTree
5
+
6
+
7
+ def parse_kml(file_path):
8
+ # Parse the KML data
9
+ data = xml.etree.ElementTree.parse(file_path)
10
+ return data
11
+
12
+
13
+ def get_coordinates(data):
14
+ # Extract the coordinates from the KML data
15
+ root_places = data.findall(".//{http://www.opengis.net/kml/2.2}Placemark")
16
+ kml_place_names = []
17
+ kml_coordinates = []
18
+ for place in root_places:
19
+ kml_place_names.append(place.find(".//{http://www.opengis.net/kml/2.2}name"))
20
+ kml_coordinates.append(place.find(".//{http://www.opengis.net/kml/2.2}coordinates"))
21
+
22
+ coordinates = {}
23
+ for kml_coordinate, place_name in zip(kml_coordinates, kml_place_names):
24
+ longitude, latitude, _ = kml_coordinate.text.split(",", 2)
25
+ coordinates[place_name.text] = (float(longitude), float(latitude))
26
+ print(f"Place: {place_name.text}, Coordinates: {coordinates[place_name.text]}")
27
+
28
+ return coordinates