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.
xodr_transform Namespace Reference

Functions

def extract_lat_lon_from_georeference (geo_text)
 
def update_georeference_text (old_text, new_lat, new_lon)
 
def rotate (x, y, angle_deg)
 
def transform_latlon (lat, lon, transformer_from_orig_to_utm, transformer_from_utm_to_new, angle_deg)
 
def transform_hdg (hdg, angle_deg)
 
def transform_xodr_file (input_path, output_path)
 

Variables

 parser = argparse.ArgumentParser(description="Transform XODR GPS-coordinates with a new geoReference and rotation.")
 
 help
 
 args = parser.parse_args()
 

Function Documentation

◆ extract_lat_lon_from_georeference()

def xodr_transform.extract_lat_lon_from_georeference (   geo_text)
Extracts lat_0 and lon_0 from the geoReference WKT string.

Definition at line 34 of file xodr_transform.py.

35 """Extracts lat_0 and lon_0 from the geoReference WKT string."""
36 lat_match = re.search(r"\+lat_0=([-+]?[0-9]*\.?[0-9]+)", geo_text)
37 lon_match = re.search(r"\+lon_0=([-+]?[0-9]*\.?[0-9]+)", geo_text)
38 if lat_match and lon_match:
39 lat = float(lat_match.group(1))
40 lon = float(lon_match.group(1))
41 return lat, lon
42 else:
43 raise ValueError("geoReference does not contain +lat_0 and +lon_0")
44
45
def extract_lat_lon_from_georeference(geo_text)

References create_two_lane_map.float.

Referenced by transform_xodr_file().

Here is the caller graph for this function:

◆ rotate()

def xodr_transform.rotate (   x,
  y,
  angle_deg 
)

Definition at line 53 of file xodr_transform.py.

53def rotate(x, y, angle_deg):
54 angle_rad = math.radians(angle_deg)
55 x_rot = x * math.cos(angle_rad) - y * math.sin(angle_rad)
56 y_rot = x * math.sin(angle_rad) + y * math.cos(angle_rad)
57 return x_rot, y_rot
58
59
def rotate(x, y, angle_deg)

Referenced by transform_latlon(), and transform_xodr_file().

Here is the caller graph for this function:

◆ transform_hdg()

def xodr_transform.transform_hdg (   hdg,
  angle_deg 
)

Definition at line 67 of file xodr_transform.py.

67def transform_hdg(hdg, angle_deg):
68 return hdg + math.radians(angle_deg)
69
70
def transform_hdg(hdg, angle_deg)

Referenced by transform_xodr_file().

Here is the caller graph for this function:

◆ transform_latlon()

def xodr_transform.transform_latlon (   lat,
  lon,
  transformer_from_orig_to_utm,
  transformer_from_utm_to_new,
  angle_deg 
)

Definition at line 60 of file xodr_transform.py.

60def transform_latlon(lat, lon, transformer_from_orig_to_utm, transformer_from_utm_to_new, angle_deg):
61 x, y = transformer_from_orig_to_utm.transform(lon, lat)
62 x_rot, y_rot = rotate(x, y, angle_deg)
63 lon_new, lat_new = transformer_from_utm_to_new.transform(x_rot, y_rot, direction='INVERSE')
64 return lat_new, lon_new
65
66
def transform_latlon(lat, lon, transformer_from_orig_to_utm, transformer_from_utm_to_new, angle_deg)

References rotate().

Referenced by transform_xodr_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ transform_xodr_file()

def xodr_transform.transform_xodr_file (   input_path,
  output_path 
)

Definition at line 71 of file xodr_transform.py.

71def transform_xodr_file(input_path, output_path):
72 tree = etree.parse(input_path)
73 root = tree.getroot()
74
75
77 new_lat = None
78 new_lon = None
79 angle_deg = 0.0
80
81
82 # Get original lat/lon from geoReference tag
83 geo_ref_tag = root.find("header/geoReference")
84 if geo_ref_tag is None or not geo_ref_tag.text:
85 raise ValueError("No geoReference tag found.")
86
87 orig_lat, orig_lon = extract_lat_lon_from_georeference(geo_ref_tag.text)
88
89 if new_lat is None or new_lon is None:
90 new_lat = orig_lat
91 new_lon = orig_lon
92
93 # Update geoReference tag for new output
94 geo_ref_tag.text = etree.CDATA(update_georeference_text(geo_ref_tag.text, new_lat, new_lon))
95
96 # Define projections
97 crs_orig = CRS.from_proj4(f"+proj=tmerc +lat_0={orig_lat} +lon_0={orig_lon} +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
98 crs_new = CRS.from_proj4(f"+proj=tmerc +lat_0={new_lat} +lon_0={new_lon} +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
99
100 transformer_to_utm = Transformer.from_crs("EPSG:4326", crs_orig, always_xy=True)
101 transformer_from_utm = Transformer.from_crs("EPSG:4326", crs_new, always_xy=True)
102
103 for elem in root.iter():
104 lat = elem.attrib.get("lat")
105 lon = elem.attrib.get("lon")
106 x = elem.attrib.get("x")
107 y = elem.attrib.get("y")
108 hdg = elem.attrib.get("hdg")
109
110 # Transform GPS-based coordinates
111 if lat and lon:
112 lat_f = float(lat)
113 lon_f = float(lon)
114 lat_new_val, lon_new_val = transform_latlon(lat_f, lon_f, transformer_to_utm, transformer_from_utm, angle_deg)
115 elem.set("lat", f"{lat_new_val:.8f}")
116 elem.set("lon", f"{lon_new_val:.8f}")
117
118 # Transform local x, y coordinates
119 if x and y:
120 x_f = float(x)
121 y_f = float(y)
122 x_rot, y_rot = rotate(x_f, y_f, angle_deg)
123 elem.set("x", f"{x_rot:.8f}")
124 elem.set("y", f"{y_rot:.8f}")
125
126 # Adjust heading
127 if hdg:
128 hdg_f = float(hdg)
129 hdg_new = transform_hdg(hdg_f, angle_deg)
130 elem.set("hdg", f"{hdg_new:.8f}")
131
132 # Write modified XML
133 tree.write(output_path, encoding="UTF-8", xml_declaration=True)
134
135
def update_georeference_text(old_text, new_lat, new_lon)
def transform_xodr_file(input_path, output_path)

References extract_lat_lon_from_georeference(), create_two_lane_map.float, rotate(), transform_hdg(), transform_latlon(), and update_georeference_text().

Here is the call graph for this function:

◆ update_georeference_text()

def xodr_transform.update_georeference_text (   old_text,
  new_lat,
  new_lon 
)
Updates the +lat_0 and +lon_0 values in a proj4 WKT string.

Definition at line 46 of file xodr_transform.py.

46def update_georeference_text(old_text, new_lat, new_lon):
47 """Updates the +lat_0 and +lon_0 values in a proj4 WKT string."""
48 new_text = re.sub(r"\+lat_0=([-+]?[0-9]*\.?[0-9]+)", f"+lat_0={new_lat}", old_text)
49 new_text = re.sub(r"\+lon_0=([-+]?[0-9]*\.?[0-9]+)", f"+lon_0={new_lon}", new_text)
50 return new_text
51
52

Referenced by transform_xodr_file().

Here is the caller graph for this function:

Variable Documentation

◆ args

xodr_transform.args = parser.parse_args()

Definition at line 143 of file xodr_transform.py.

◆ help

xodr_transform.help

Definition at line 140 of file xodr_transform.py.

◆ parser

xodr_transform.parser = argparse.ArgumentParser(description="Transform XODR GPS-coordinates with a new geoReference and rotation.")

Definition at line 139 of file xodr_transform.py.