def setUp(self): """Load the osm file and convert it to a scenario.""" try: commonroad_reader = CommonRoadFileReader( os.path.dirname(os.path.realpath(__file__)) + f"/osm_xml_test_files/{self.xml_file_name}.xml") scenario, _ = commonroad_reader.open() except etree.XMLSyntaxError as xml_error: print(f"SyntaxERror: {xml_error}") print( "There was an error during the loading of the selected CommonRoad file.\n" ) l2osm = L2OSMConverter(self.proj_string) self.osm = l2osm(scenario)
def openPath(self, path): """ Args: path: Returns: """ filename = os.path.basename(path) self.inputCommonRoadFile.setText(filename) try: # fh = open(path, "rb") # data = fh.read() # fh.close() commonroad_reader = CommonRoadFileReader(path) scenario, _ = commonroad_reader.open() except etree.XMLSyntaxError as e: errorMsg = "Syntax Error: {}".format(e) QMessageBox.warning( self, "CommonRoad XML error", "There was an error during the loading of the selected CommonRoad file.\n\n{}".format( errorMsg ), QMessageBox.Ok, ) return except Exception as e: errorMsg = "{}".format(e) QMessageBox.warning( self, "CommonRoad XML error", "There was an error during the loading of the selected CommonRoad file.\n\n{}".format( errorMsg ), QMessageBox.Ok, ) return self.openScenario(scenario)
def commonroad_to_osm(args, output_name: str): """Convert from CommonRoad to OSM. Args: args: Object containing parsed arguments. output_name: Name of file where result should be written to. """ try: commonroad_reader = CommonRoadFileReader(args.input_file) scenario, _ = commonroad_reader.open() except etree.XMLSyntaxError as xml_error: print(f"SyntaxERror: {xml_error}") print( "There was an error during the loading of the selected CommonRoad file.\n" ) l2osm = L2OSMConverter(args.proj) osm = l2osm(scenario) with open(f"{output_name}", "wb") as file_out: file_out.write( etree.tostring(osm, xml_declaration=True, encoding="UTF-8", pretty_print=True))