Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
RouteCreation_KML2CSV.py
Go to the documentation of this file.
1#!/usr/bin/python3
2
3# Copyright (C) 2018-2021 LEIDOS.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16
17import xml.etree.ElementTree as ET
18import xml.dom.minidom
19import json
20import argparse
21from math import *
22
24 """
25 Convert the point data located in filename into a lane element
26 """
27
28 out = []
29 xml = ET.parse(filename)
30 root = xml.getroot()
31
32 for coord in root.findall(".//{http://www.opengis.net/kml/2.2}coordinates"):
33 (lon, lat, _) = coord.text.split(",")
34 out.append((lat.strip(), lon.strip()))
35
36 return out
37
38def main():
39 parser = argparse.ArgumentParser("Convert a KML file into a CSV file, to further process with RouteCreation_CSV2Yaml.py")
40 parser.add_argument("kml_input", help="KML input containing the desired route geometry")
41 parser.add_argument("default_speed", help="The default speed limit along the route")
42 parser.add_argument("csv_output", help="The file to write the CSV out to")
43 args = parser.parse_args()
44 print("Converting {} to CSV as {}".format(args.kml_input, args.csv_output))
45 output = open(args.csv_output, "w")
46 output.write("Latitude,Longitude,Speed\n")
47
48 waypoints = convertKMLToWaypoints(args.kml_input)
49 print("{} waypoints found. Using speed {} for all. Writing output...".format(len(waypoints), args.default_speed))
50 count = 0
51 for waypoint in waypoints:
52 output.write("{},{},{}\n".format(waypoint[0], waypoint[1], args.default_speed))
53 count += 1
54 print("Wrote {} entries to {}.".format(count, args.csv_output))
55
56
57if __name__ == "__main__":
58 print("Running RouteCreation_KML2CSV.py...")
59 main()
60
def convertKMLToWaypoints(filename)