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

Functions

def filter_xodr (input_file, output_file, road_ids_to_keep)
 

Variables

dictionary road_ids_to_keep = {"23"}
 
string input_file = "original_map.xodr"
 
string output_file = "filtered_map.xodr"
 

Detailed Description

Purpose:
This script filters an .xodr map file to retain only a specified subset of roads based on their IDs.

Key Features:

- Allows user to define a set of road IDs to keep (road_ids_to_keep).
- Removes all roads and junctions not associated with the specified IDs.
- Outputs a new .xodr file containing only the filtered elements.

Use Case:
Creating a trimmed-down version of a map with only selected road segments for focused simulation or testing.

Function Documentation

◆ filter_xodr()

def filter_roads.filter_xodr (   input_file,
  output_file,
  road_ids_to_keep 
)

Definition at line 24 of file filter_roads.py.

24def filter_xodr(input_file, output_file, road_ids_to_keep):
25 tree = etree.parse(input_file)
26 root = tree.getroot()
27
28 # Remove roads not in the list
29 for road in root.findall("road"):
30 if road.get("id") not in road_ids_to_keep:
31 root.remove(road)
32
33 # Remove unrelated junctions
34 for junction in root.findall("junction"):
35 remove = True
36 for connection in junction.findall("connection"):
37 if (connection.get("incomingRoad") in road_ids_to_keep or
38 connection.get("connectingRoad") in road_ids_to_keep):
39 remove = False
40 break
41 if remove:
42 root.remove(junction)
43
44 # Write the result to output
45 tree.write(output_file, pretty_print=True, xml_declaration=True, encoding='UTF-8')
46 print(f"Filtered XODR written to: {output_file}")
47
48# === Run the filter ===
def filter_xodr(input_file, output_file, road_ids_to_keep)
Definition: filter_roads.py:24

References filter_xodr().

Referenced by filter_xodr().

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

Variable Documentation

◆ input_file

string filter_roads.input_file = "original_map.xodr"

Definition at line 21 of file filter_roads.py.

◆ output_file

string filter_roads.output_file = "filtered_map.xodr"

Definition at line 22 of file filter_roads.py.

◆ road_ids_to_keep

dictionary filter_roads.road_ids_to_keep = {"23"}

Definition at line 17 of file filter_roads.py.