Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/net/xmlconnections_mapEdges.py
169673 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2009-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file xmlconnections_mapEdges.py
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @date 2009-08-01
18
19
"""
20
Reads edge id replacements from "edgemap.txt"; the format of this file is
21
<OLD_EDGE_ID>-><NEW_EDGE_ID>
22
Reads the given connections file <CONNECTIONS> and replaces old edge names by new.
23
The result is written to <CONNECTIONS>.mod.xml
24
25
Call: xmlconnections_mapEdges.py <CONNECTIONS>
26
"""
27
from __future__ import absolute_import
28
from __future__ import print_function
29
30
import sys
31
32
if len(sys.argv) < 2:
33
print("Usage: " + sys.argv[0] + " <CONNECTIONS>")
34
sys.exit()
35
36
# read map
37
mmap = {}
38
fdi = open("edgemap.txt")
39
for line in fdi:
40
if line.find("->") < 0:
41
continue
42
(orig, dest) = line.strip().split("->")
43
dest = dest.split(",")
44
mmap[orig] = dest
45
fdi.close()
46
47
fdi = open(sys.argv[1])
48
fdo = open(sys.argv[1] + ".mod.xml", "w")
49
for line in fdi:
50
for orig in mmap:
51
line = line.replace(
52
'from="' + orig + '"', 'from="' + mmap[orig][-1] + '"')
53
line = line.replace('to="' + orig + '"', 'to="' + mmap[orig][0] + '"')
54
fdo.write(line)
55
fdi.close()
56
fdo.close()
57
58