Path: blob/main/tests/complex/netconvert/osm_roundtrip/runner.py
169685 views
#!/usr/bin/env python1# -*- coding: utf-8 -*-2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo3# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file runner.py15# @author Jakob Erdmann16# @author Laura Bieker17# @author Michael Behrisch18# @date 2011-05-271920"""21import osm network22then import the built network again and check for idempotency23"""24from __future__ import absolute_import2526import sys27import os28import subprocess29import difflib30if "SUMO_HOME" in os.environ:31sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))32import sumolib # noqa3334osm_input = 'osm.xml'35net_output = 'from_osm'36net_output2 = 'net'3738netconvert = sumolib.checkBinary('netconvert')3940# filter header and projection clause414243def filtered(file_name, start_element):44skippedHeader = False45with open(file_name) as f:46for line in f:47if start_element in line:48skippedHeader = True49if not skippedHeader:50continue51if '<location' in line:52continue53if '<projection' in line:54continue55yield line565758def get_filtered_lines(prefix):59result = []60for suffix, start_element in [61('.net.xml', '<net '),62('.nod.xml', '<nodes '),63('.edg.xml', '<edges '),64('.con.xml', '<connections '),65('.tll.xml', '<tlLogics ')]:66result += list(filtered(prefix + suffix, start_element))67return result686970args1 = [netconvert,71'--no-internal-links',72'--osm-files', osm_input, '--proj.utm',73'-R', '--ramps.guess',74'--tls.guess', '--tls.join',75'--junctions.join',76'--plain-output-prefix', net_output,77'--output', net_output + '.net.xml']7879args2 = [netconvert,80'--sumo-net-file', net_output + '.net.xml',81'--no-internal-links',82'--offset.disable-normalization',83'--plain-output-prefix', net_output2,84'--output', net_output2 + '.net.xml']8586subprocess.call(args1)87subprocess.call(args2)8889fromlines = get_filtered_lines(net_output)90tolines = get_filtered_lines(net_output2)91# with open('fromlines','w') as f: f.write('\n'.join(fromlines))92# with open('tolines','w') as f: f.write('\n'.join(tolines))93sys.stderr.writelines(difflib.unified_diff(fromlines, sumolib.fpdiff.fpfilter(fromlines, tolines, 0.0201)))949596