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

Variables

float new_lat_0 = 0.0
 
float new_lon_0 = 0.0
 
float rotate_lat = 0.0
 
float rotate_lon = 0.0
 
float rotation_deg = 0.0
 
 theta_rad = math.radians(rotation_deg)
 
 parser = argparse.ArgumentParser(description="Relocate and rotate OSM map geometry around a new reference point.")
 
 help
 
 args = parser.parse_args()
 
 tree = etree.parse(args.input_file)
 
 root = tree.getroot()
 
 geo_ref_elem = root.find("geoReference")
 
 old_proj_str = geo_ref_elem.text.strip()
 
string new_proj_str = f"+proj=tmerc +lat_0={new_lat_0} +lon_0={new_lon_0} +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +geoidgrids=egm96_15.gtx +vunits=m +no_defs"
 
 crs_wgs84 = CRS.from_epsg(4326)
 
 crs_old = CRS.from_proj4(old_proj_str)
 
 crs_new = CRS.from_proj4(new_proj_str)
 
 to_old_xy = Transformer.from_crs(crs_wgs84, crs_old, always_xy=True)
 
 to_new_latlon = Transformer.from_crs(crs_new, crs_wgs84, always_xy=True)
 
 text
 
 xs_old
 
 ys_old
 
 lat = float(node.get("lat"))
 
 lon = float(node.get("lon"))
 
 x_old
 
 y_old
 
 cx_old = np.mean(xs_old)
 
 cy_old = np.mean(ys_old)
 
 to_new_xy = Transformer.from_crs(crs_wgs84, crs_new, always_xy=True)
 
 rotate_x
 
 rotate_y
 
 offset_x = rotate_x - cx_old
 
 offset_y = rotate_y - cy_old
 
 x = xs_old[i] + offset_x
 
 y = ys_old[i] + offset_y
 
 x_rel
 
 y_rel
 
 x_rot = x_rel * math.cos(theta_rad) - y_rel * math.sin(theta_rad)
 
 y_rot = x_rel * math.sin(theta_rad) + y_rel * math.cos(theta_rad)
 
 new_lon
 
 new_lat
 
 output_file
 
 pretty_print
 
 True
 
 xml_declaration
 
 encoding
 

Detailed Description

This script relocates and optionally rotates an OpenStreetMap (OSM) file that uses a custom geoReference. It's useful when you want to:
- Move a local map to a new geographic location.
- Preserve geometry, scale, and layout.
- Rotate the map around its origin (for alignment or testing).
---

Steps:

1. Read the input OSM XML file.
2. Extract the original geoReference (a Transverse Mercator projection centered at some latitude/longitude).
3. Convert each nodes lat/lon to projected (X, Y) coordinates using the original projection.
4. Apply a 2D rotation (optional) around the local origin (0, 0).
5. Transform the rotated (X, Y) into new lat/lon coordinates using a new projection centered at a new location.
6. Update the <geoReference> tag to reflect the new center.
7. Save the updated OSM XML file with transformed coordinates.

---

Inputs:

1- input_file.osm: An OSM XML file that:
- Contains a <geoReference> string using +proj=tmerc
- Has <node> elements with lat and lon attributes

2- output_file.osm: The transformed OSM map name that:
- All node positions have been relocated and optionally rotated
- The <geoReference> tag is updated to match the new map center
- The map geometry is preserved in relative terms but relocated globally

---

Parameters to adjust to transform:

- rotation_deg: Rotation angle in degrees (positive = counter-clockwise)
- new_lat_0, new_lon_0: New center location in geographic coordinates (latitude, longitude)

--

Dependency:
pip install lxml pyproj

--
how to run the script:

python osm_transform.py suntrax.osm suntrax_transformed.osm

Variable Documentation

◆ args

osm_transform.args = parser.parse_args()

Definition at line 73 of file osm_transform.py.

◆ crs_new

osm_transform.crs_new = CRS.from_proj4(new_proj_str)

Definition at line 96 of file osm_transform.py.

◆ crs_old

osm_transform.crs_old = CRS.from_proj4(old_proj_str)

Definition at line 95 of file osm_transform.py.

◆ crs_wgs84

osm_transform.crs_wgs84 = CRS.from_epsg(4326)

Definition at line 94 of file osm_transform.py.

◆ cx_old

osm_transform.cx_old = np.mean(xs_old)

Definition at line 117 of file osm_transform.py.

◆ cy_old

osm_transform.cy_old = np.mean(ys_old)

Definition at line 118 of file osm_transform.py.

◆ encoding

osm_transform.encoding

Definition at line 152 of file osm_transform.py.

◆ geo_ref_elem

osm_transform.geo_ref_elem = root.find("geoReference")

Definition at line 80 of file osm_transform.py.

◆ help

osm_transform.help

Definition at line 71 of file osm_transform.py.

◆ lat

osm_transform.lat = float(node.get("lat"))

◆ lon

osm_transform.lon = float(node.get("lon"))

◆ new_lat

osm_transform.new_lat

Definition at line 141 of file osm_transform.py.

◆ new_lat_0

float osm_transform.new_lat_0 = 0.0

Definition at line 58 of file osm_transform.py.

◆ new_lon

osm_transform.new_lon

Definition at line 141 of file osm_transform.py.

◆ new_lon_0

float osm_transform.new_lon_0 = 0.0

Definition at line 59 of file osm_transform.py.

◆ new_proj_str

string osm_transform.new_proj_str = f"+proj=tmerc +lat_0={new_lat_0} +lon_0={new_lon_0} +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +geoidgrids=egm96_15.gtx +vunits=m +no_defs"

Definition at line 90 of file osm_transform.py.

◆ offset_x

osm_transform.offset_x = rotate_x - cx_old

Definition at line 125 of file osm_transform.py.

◆ offset_y

osm_transform.offset_y = rotate_y - cy_old

Definition at line 126 of file osm_transform.py.

◆ old_proj_str

osm_transform.old_proj_str = geo_ref_elem.text.strip()

Definition at line 85 of file osm_transform.py.

◆ output_file

osm_transform.output_file

Definition at line 152 of file osm_transform.py.

◆ parser

osm_transform.parser = argparse.ArgumentParser(description="Relocate and rotate OSM map geometry around a new reference point.")

Definition at line 70 of file osm_transform.py.

◆ pretty_print

osm_transform.pretty_print

Definition at line 152 of file osm_transform.py.

◆ root

osm_transform.root = tree.getroot()

Definition at line 77 of file osm_transform.py.

Referenced by arbitrator::TreePlanner.generate_plan().

◆ rotate_lat

float osm_transform.rotate_lat = 0.0

Definition at line 61 of file osm_transform.py.

◆ rotate_lon

float osm_transform.rotate_lon = 0.0

Definition at line 62 of file osm_transform.py.

◆ rotate_x

osm_transform.rotate_x

Definition at line 122 of file osm_transform.py.

◆ rotate_y

osm_transform.rotate_y

Definition at line 122 of file osm_transform.py.

◆ rotation_deg

float osm_transform.rotation_deg = 0.0

Definition at line 65 of file osm_transform.py.

◆ text

osm_transform.text

Definition at line 104 of file osm_transform.py.

◆ theta_rad

osm_transform.theta_rad = math.radians(rotation_deg)

Definition at line 67 of file osm_transform.py.

◆ to_new_latlon

osm_transform.to_new_latlon = Transformer.from_crs(crs_new, crs_wgs84, always_xy=True)

Definition at line 100 of file osm_transform.py.

◆ to_new_xy

osm_transform.to_new_xy = Transformer.from_crs(crs_wgs84, crs_new, always_xy=True)

Definition at line 121 of file osm_transform.py.

◆ to_old_xy

osm_transform.to_old_xy = Transformer.from_crs(crs_wgs84, crs_old, always_xy=True)

Definition at line 99 of file osm_transform.py.

◆ tree

◆ True

osm_transform.True

Definition at line 152 of file osm_transform.py.

◆ x

osm_transform.x = xs_old[i] + offset_x

Definition at line 130 of file osm_transform.py.

◆ x_old

osm_transform.x_old

Definition at line 113 of file osm_transform.py.

◆ x_rel

osm_transform.x_rel

Definition at line 134 of file osm_transform.py.

◆ x_rot

osm_transform.x_rot = x_rel * math.cos(theta_rad) - y_rel * math.sin(theta_rad)

Definition at line 135 of file osm_transform.py.

◆ xml_declaration

osm_transform.xml_declaration

Definition at line 152 of file osm_transform.py.

◆ xs_old

osm_transform.xs_old

Definition at line 109 of file osm_transform.py.

◆ y

osm_transform.y = ys_old[i] + offset_y

Definition at line 131 of file osm_transform.py.

◆ y_old

osm_transform.y_old

Definition at line 113 of file osm_transform.py.

◆ y_rel

osm_transform.y_rel

Definition at line 134 of file osm_transform.py.

◆ y_rot

osm_transform.y_rot = x_rel * math.sin(theta_rad) + y_rel * math.cos(theta_rad)

Definition at line 136 of file osm_transform.py.

◆ ys_old

osm_transform.ys_old

Definition at line 109 of file osm_transform.py.