Skip to content

Error when a traffic sign is never referenced from a lanelet

Currently, when reading a Scenario where there is a traffic sign (here with ID 182) that is never referenced from any lanelet:

Traceback (most recent call last):
  File "visualize_cr.py", line 66, in <module>
    scenario, planning_problem_set = CommonRoadFileReader(input_d).open()
  File "/home/niels/.local/share/virtualenvs/ind_to_commonroad-odHG8oUv/lib/python3.8/site-packages/commonroad/common/file_reader.py", line 83, in open
    scenario = self._open_scenario()
  File "/home/niels/.local/share/virtualenvs/ind_to_commonroad-odHG8oUv/lib/python3.8/site-packages/commonroad/common/file_reader.py", line 102, in _open_scenario
    scenario = ScenarioFactory.create_from_xml_node(self._tree, self._dt, self._benchmark_id,
  File "/home/niels/.local/share/virtualenvs/ind_to_commonroad-odHG8oUv/lib/python3.8/site-packages/commonroad/common/file_reader.py", line 203, in create_from_xml_node
    scenario.add_objects(LaneletNetworkFactory.create_from_xml_node(xml_node))
  File "/home/niels/.local/share/virtualenvs/ind_to_commonroad-odHG8oUv/lib/python3.8/site-packages/commonroad/common/file_reader.py", line 336, in create_from_xml_node
    lanelet_network.add_traffic_sign(TrafficSignFactory.create_from_xml_node(traffic_sign_node, country,
  File "/home/niels/.local/share/virtualenvs/ind_to_commonroad-odHG8oUv/lib/python3.8/site-packages/commonroad/common/file_reader.py", line 730, in create_from_xml_node
    first_occurrence=first_traffic_sign_occurence[traffic_sign_id],
KeyError: 182

This is due to the fact that the method for initializing traffic sign first occurences does only initialize the sets based on the traffic signs that are referenced from any lanelet.

While it is not very useful to have a traffic sign inside a scenario without a lanelet referencing it, I feel that this case should be handled (i.e. by assertions) and a meaningful error message thrown. (I am quite sure that the xsd specification cannot handle this so I assume a runtime check will be necessary)

Edited by Ghost User