import xml import xml.dom import xml.etree import xml.etree.ElementTree def parse_kml(file_path): # Parse the KML data data = xml.etree.ElementTree.parse(file_path) return data def get_coordinates(data): # Extract the coordinates from the KML data root_places = data.findall(".//{http://www.opengis.net/kml/2.2}Placemark") kml_place_names = [] kml_coordinates = [] for place in root_places: kml_place_names.append(place.find(".//{http://www.opengis.net/kml/2.2}name")) kml_coordinates.append(place.find(".//{http://www.opengis.net/kml/2.2}coordinates")) coordinates = {} for kml_coordinate, place_name in zip(kml_coordinates, kml_place_names): longitude, latitude, _ = kml_coordinate.text.split(",", 2) coordinates[place_name.text] = (float(longitude), float(latitude)) print(f"Place: {place_name.text}, Coordinates: {coordinates[place_name.text]}") return coordinates